错误:scatchpad.exe中0x760ab9bc处的未处理异常:Microsoft C ++异常

时间:2012-03-06 04:01:56

标签: c++ image-processing opencv computer-vision

此代码工作正常,正在输出行人的动态强度图像。那个视频的大小是320 x 240.现在,我必须得到一个类似的图像,但有人挥手,而不是走路。因此,我使用了一个新的视频“挥手”。此视频的大小为640 x 480.我将处理帧大小的代码的所有部分更改为此新大小,但我一直收到未处理的异常错误。请有人能够解释为什么会这样吗?我将不胜感激。

#include "cv.h"
#include "highgui.h"
#include "iostream"

using namespace std;
int main( int argc, char* argv ) {

CvCapture *capture = NULL;
capture = cvCaptureFromFile("C:\\walking\\man waving.wmv");
if(!capture){
    return -1;
}

IplImage* color_frame = NULL;
IplImage* gray_frame = NULL ;
IplImage* res_frame = NULL;
IplImage* fin_frame = NULL;
CvMat* subimage1 = NULL ;
CvMat* subimage2 = NULL ;

fin_frame = cvCreateImage(cvSize(640,480), IPL_DEPTH_32F, 1);

int thresh_frame = 17;
int frameCount=0;//Counts every 5 frames

cvNamedWindow( "result", 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), IPL_DEPTH_8U, 1);
    res_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), IPL_DEPTH_8U, 1);

    subimage1 = cvCreateMat(640, 480, 1);
    subimage2 = cvCreateMat(640, 480, 1);

    frameCount++;

    if(frameCount==5)
    {
        cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
        cvThreshold(gray_frame, gray_frame, thresh_frame, 255, CV_THRESH_TOZERO_INV);
        cvErode(gray_frame, gray_frame, NULL, 1);
        cvDilate(gray_frame, gray_frame, NULL, 1);

        CvRect rect = cvBoundingRect((gray_frame), 0);

        int x = rect.x;
        int y = rect.y;
        int width = rect.width;
        int height = rect.height;
        int x1 = (x+width);
        int y1 = (y+height); 
        int x_new = (640-width)/2;
        int y_new = (480-height)/2;

        cvRectangle( gray_frame, cvPoint(x, y),cvPoint(x1,y1),CV_RGB(0, 0, 255) , 7, 8, 0);
        cvGetSubRect(gray_frame, subimage1, cvRect(x, y, width, height));
        cvGetSubRect(res_frame, subimage2, cvRect(x_new, y_new, width, height));
        cvCopy(subimage1, subimage2, 0);
        cvRunningAvg(res_frame, fin_frame, 0.01, 0);
        frameCount=0;
    }
    cvShowImage("result", fin_frame) ;

    char c = cvWaitKey(33);
    if( c == 27 ) break;
}

cvReleaseImage(&color_frame);
cvReleaseImage(&gray_frame);
cvReleaseImage(&res_frame);
cvReleaseImage(&fin_frame);
cvReleaseCapture( &capture );
cvDestroyWindow( "result" );

return 0;
}

0 个答案:

没有答案