2012-02-19 96 views
-1

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

回答

0
cout << "Area - : " << m00 << endl; 

功能cvGetSpatialMoment检索空间矩,这在图像矩的情况下,被定义为:

Mji=sumx,y(I(x,y)•xj•yi) 

其中I(x,y)是像素(x, y)的强度。

空间时刻m00就像物体的质量。它不包含x,y信息。在所有我的平均x位置是average(x) = sum(density(x)*x_i)I(x,y)就像密度函数,但这里是像素的强度。如果你不希望你的结果根据光照改变,你可能想要使矩阵成为一个二进制矩阵。像素既可以是对象的一部分也可以不是。按照上述公式将灰度图转换为灰度图。

Area = average(x) * average(y) 

所以要

Area = m01 * m10 

M00基本上总结了灰度级在图像中的所有像素。没有空间意义。虽然如果你不把你的图像转换成二进制,你可能希望除以m00来“正常化”它。

0

您可以使用MEI和MHI图像来识别运动。使用50帧/ 1更新MHI图像并获取片段运动并通过cvMotion创建运动,之后您需要将mathanan与训练数据区分开来。我是越南人。而英语我很糟糕。