I want to subtract green background from webcam video. bellow shows how I get the video from webcam
public static void main(String[] args) {
CvCapture capture =cvCreateCameraCapture(CV_CAP_ANY); //
IplImage frame;
IplImage grayimg = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
for(;;)
{
frame = cvQueryFrame(capture);
if(frame == null)
{
System.out.println("ERROR: NO Video File");
break;
}
cvShowImage("Video",hsvThreshold(frame));
char c = (char) cvWaitKey(30);
if(c==27) break;
}
cvReleaseCapture(capture);
cvDestroyWindow("Video");
}
My Image Mask is retun IplImage of hsvThreshold(frame)
this function.At that time original frame is frame
so I want to extrac the mask
hsvThreshold(frame)
is like this
public static IplImage hsvThreshold(IplImage orgImg) {
// 8-bit, 3- color =(RGB)
IplImage imgHSV = cvCreateImage(cvGetSize(orgImg), 8, 3);
System.out.println(cvGetSize(orgImg));
cvCvtColor(orgImg, imgHSV, CV_BGR2HSV);
// 8-bit 1- color = monochrome
IplImage imgThreshold = cvCreateImage(cvGetSize(orgImg), 8, 1);
cvInRangeS(imgHSV, cvScalar(70, 50, 50, 0), cvScalar(150, 200, 200, 0), imgThreshold);
cvReleaseImage(imgHSV);
cvSmooth(imgThreshold, imgThreshold, CV_GAUSSIAN, 13);
cvNot(imgThreshold,imgThreshold);
return imgThreshold;
}