我做步行使用的OpenCV和C++,我想以達到在所提供的圖像觀察到的效果來創建掩模或複製的圖像的運動識別斑點。 。以下是所得的人行走的斑被看到的圖像 的說明。然後,創建原始幀的蒙板圖像或複製圖像,二進制人類斑點現在被掩蔽,而未蒙版像素現在被設置爲零。結果是黑色背景中提取的人體。下圖顯示了人類斑點如何被提取然後被掩蓋。 這是爲視頻序列的每個第5幀完成的。到目前爲止我的代碼包括獲得每5幀,灰度化它,發現所有的斑的面積,並且將閾值來獲得一個二進制圖像,其中或多或少,只有人類斑塊爲白色,而圖像的其餘部分是黑色。現在,我試圖提取人體,但我不知道如何繼續。請幫幫我。掩蔽從二進制圖像
#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;
}
我也想上傳,我使用的代碼中的視頻,但我不知道怎麼在這裏上傳,因此,如果有人可以幫助我了這一點。我想提供儘可能多的信息w.r.t.我的問題。
在一個側面說明黑色對應的像素,休息不應該被使用的方式!使用do {},然後在那裏進行檢查。 – 2012-02-21 12:21:34
@MartinKristiansen我是新來的openCV和C++,所以一旦代碼工作,我很高興。那個休息是不是可以接受的? – 2012-02-21 16:12:57
它使controlflow配發的透明度較低,搞清楚當while循環退出是真的不清晰,會得到很多不太清楚,如果代碼的增長。 – 2012-02-22 09:18:57