Reputation: 81
I have a background image and foreground image. Their point of view are equal. But shadows are different. I am going to extract contours of the legs.
I've applied background difference, but it doesn't work very well. Please someone tell me the good way. You can see the images below.
Thanks.
Upvotes: 2
Views: 500
Reputation: 2533
If you're interested solely in extracting the image of a leg, then HSV-based skin detection, followed by repetitive dilation should produce better results. See code below:
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat b=imread("b2.png");//back
Mat f=imread("f2.png");//fore
Mat hsv_th;
cvtColor(b,b,CV_BGR2HSV);
cvtColor(f,f,CV_BGR2HSV);
inRange(f,Scalar(0,100,0),Scalar(100,255,100),hsv_th);
dilate(hsv_th,hsv_th,cv::Mat());
dilate(hsv_th,hsv_th,cv::Mat());
dilate(hsv_th,hsv_th,cv::Mat());
dilate(hsv_th,hsv_th,cv::Mat());
for(;;)
{
imshow("fore",f);
imshow("hsv",hsv_th);
char c=waitKey(10);
if(c=='b')//break when 'b' is pressed
{
break;
}
}
return 0;
}
Upvotes: 1