我正在研究步行的运动识别项目,涉及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;
}