Binary blob masking

I perform motion recognition using openCV and C ++, and I would like to create a mask or copied image to achieve the effect observed on the image. extracted human . The following is an explanation of the images. It can be seen that the result is human walking. Then a mask image or a copied image of the original frame is created, now the binary human blob is masked, and unmasked pixels are now set to zero. The result is an extracted human body with a black background. The diagram below shows how a human drop is removed and then masked. This must be done for every fifth frame of the video sequence. My code so far is to get every fifth frame, make it a gray scale, find the areas of all the blocks, and apply the threshold value to get a binary image, where more or less, only a human drop is white and the rest of the image is black . Now I am trying to extract the human body, but I do not know how to proceed. Please help me.

#include "cv.h" #include "highgui.h" #include "iostream" using namespace std; int main( int argc, char* argv ) { CvCapture *capture = NULL; capture = cvCaptureFromAVI("C:\\walking\\lady walking.avi"); if(!capture){ return -1; } IplImage* color_frame = NULL; IplImage* gray_frame = NULL ; int thresh_frame = 28; CvMoments moments; int frameCount=0;//Counts every 5 frames cvNamedWindow( "walking", CV_WINDOW_AUTOSIZE ); while(1) { color_frame = cvQueryFrame( capture );//Grabs the frame from a file if( !color_frame ) break; gray_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), color_frame->depth, 1); if( !color_frame ) break;// If the frame does not exist, quit the loop frameCount++; if(frameCount==5) { cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY); cvThreshold(gray_frame, gray_frame, thresh_frame, 255, CV_THRESH_BINARY); cvErode(gray_frame, gray_frame, NULL, 1); cvDilate(gray_frame, gray_frame, NULL, 1); cvMoments(gray_frame, &moments, 1); double m00; m00 = cvGetCentralMoment(&moments, 0,0); cvShowImage("walking", gray_frame); frameCount=0; } char c = cvWaitKey(33); if( c == 27 ) break; } double m00 = (double)cvGetCentralMoment(&moments, 0,0); cout << "Area - : " << m00 << endl; //area of lady walking = 39696. Therefore, using new threshold area as 30 for this video //area of walking man = 67929 cvReleaseImage(&color_frame); cvReleaseImage(&gray_frame); cvReleaseCapture( &capture ); cvDestroyWindow( "walking" ); return 0; } 

I would also like to download the video that I use in the code, but I don’t know how to upload it here, so if someone can help me with this. I want to provide as much information as possible wrt my question.

+4
source share
1 answer

The easiest way is to find the largest frame in the image (cvfind outlines can be a necessary function), then you set blac to all other drops (scannig all outlines and using cvfloadfill). finally, you scan the entire binary image, if the pixel in question is white, you do nothing, if the pixel is black, you set the corresponding pixel of the fifth frame to black

+1
source

All Articles