2016-04-26 8 views
1

私は動きの検出にopencvを使用する初心者です。私はコードを実行し、人間の検出のための最終的な決定が必要でした。問題は、コードが最終決定のために表示されなかったことです。誰も助けて、コードの問題点を教えてください。問題のために解決策がありますか?opencvを使った動き検出のエラー

int main() 
{ 
    Mat frame; 
    Mat resize_blur_Img; 
    Mat fgMaskMOG; 
    Mat fgMaskMOG2; 
    Mat fgMaskGMG; 
    Mat binaryImg; 

Ptr<BackgroundSubtractor>pMOG; 
pMOG = new BackgroundSubtractorMOG(); 
char filename[100] = "C:/Users/user/Desktop/Child Entrapment Prevention System/Motion Only/64.avi"; 

VideoCapture stream1(filename); 
Mat element = getStructuringElement(MORPH_RECT, Size(7, 7), Point(3, 3)); 
int frame_count = 0; 
int detected_motion_count=0; 


while (true) 
{ 
    if (!(stream1/*cap*/.read(frame))) 
     break; 

    frame_count++; 

    resize(frame, resize_blur_Img, Size(frame.size().width, frame.size().height)); 

    //BLUR 
    pMOG->operator()(resize_blur_Img, fgMaskMOG,-1); 

    //MORPHOLOGY 
    morphologyEx(fgMaskMOG, binaryImg, CV_MOP_CLOSE, element); 

    //shadow delete (BINARY) 
    threshold(binaryImg, binaryImg, 128, 255, CV_THRESH_BINARY); //(input array, output array, threshold value, max value to use threshold type, threshold type) 

    imshow("Origin", resize_blur_Img); 
    imshow("MOG", fgMaskMOG); 

    //PIXEL 
    int TotalNumberOfPixels = fgMaskMOG.rows*fgMaskMOG.cols; 
    cout << "The number of pixels that are 255 is " << countNonZero(fgMaskMOG) << endl; 


    if (countNonZero(fgMaskMOG) >= 1) 
    { 

     detected_motion_count++; 
     printf("Motion DETECTED !\n\n", countNonZero(fgMaskMOG)); 
    } 
    else 
    { 
     printf("Motion NOT DETECTED!\n\n", countNonZero(fgMaskMOG)); 
    } 

} 

printf("count of frames : %d \n", frame_count); 
printf("count motion detected: %d \n", detected_motion_count); 
printf("Motion Found %d percent of frames ! \n", (int)(100 * detected_motion_count/frame_count)); 

if ((float)(detected_motion_count/frame_count) ==0.45) 
{ 
    printf("\n\n------------------------FINAL DECISION------------------------------"); 
    printf("HUMAN DETECTED \n\n"); 
} 
getchar(); 

} 
+0

あなたはどんな出力を期待していますか? –

+0

は、printf( "フレーム数:%d \ n"、frame_count)の値を提供します。 printf(「カウント動作が検出されました:%d \ n」、detected_motion_count); – piyushj

+0

私の予想される出力は、検出された動きがフレーム全体から45%以上である場合、 "人間が検出しました"という表示です。 – CBP

答えて

1

あなたはこのように見えるように、このライン

if ((float)(detected_motion_count/frame_count) ==0.45) 

を変更する必要があります。

if (((float)detected_motion_count/(float)frame_count) >=0.45) 

detected_motion_count以来とframe_count整数は整数divisonが別の方法で使用され、結果は常に0である、あります。 (少なくともframe_countdetected_motion_countより大きい限り)

また、比率がより大きい場合は、のしきい値が正確にしきい値に等しくない場合に検出を出力することもできます。

+0

ありがとうございます..それは私の問題を解決する – CBP

関連する問題