2012-02-19 25 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與訓練數據區分開來。我是越南人。而英語我很糟糕。