我正在研究步行的運動識別項目,涉及openCV和C++。我已經到達了需要找到人類斑點區域的算法階段。我已經加載了視頻,將其轉換爲灰度,並對其進行閾值處理,以獲得白色區域的二值圖像,以顯示除了其他白色區域之外的人類行走。我需要找到每個白色區域的區域來確定人類斑點的面積,因爲這個區域的面積將大於其他白色區域的面積。請仔細閱讀我的代碼,並向我解釋輸出結果,因爲我得到了一個40872的區域,我不知道這意味着什麼。這是我的代碼。我想上傳我用過的視頻,但我不知道如何:/如果有人能告訴我如何上傳我用過的視頻,請做,因爲這是我能夠獲得有關此特定視頻的幫助的唯一方式。我真的希望有人能幫助我。使用cvMoments的對象的區域
#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 = 70;
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 = cvGetSpatialMoment(&moments, 0,0);
cvShowImage("walking", gray_frame);
frameCount=0;
}
char c = cvWaitKey(33);
if(c == 27) break;
}
double m00 = (double)cvGetSpatialMoment(&moments, 0,0);
cout << "Area - : " << m00 << endl;
cvReleaseImage(&color_frame);
cvReleaseImage(&gray_frame);
cvReleaseCapture(&capture);
cvDestroyWindow("walking");
return 0;
}