Reputation: 321
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;
}
Upvotes: 0
Views: 155
Reputation: 1531
If you want to copy your image without the pixels in the mask you can use the function cvCopy(origImage,destImage,mask);
. See this SO post for more info.
I do recommend you to switch to the C++ API though, it is much easier to understand and less concern about releasing images and memory leaks.
EDIT: You can also copy one image onto another without cvCopy. You can fid the code for that in this post: Copying a portion of an IplImage into another Iplimage (that is of same size is the source)
Upvotes: 1