使用javacv opencv跟踪矩形移动对象

时间:2012-12-12 20:16:17

标签: java opencv javacv

我正在做项目的一部分,使用javacv在视频中围绕移动对象创建矩形。我使用这段代码,当我运行这个时,我得到一个名为“此指针地址为空”的错误。有人可以帮帮我吗?谢谢

    while(true) {
        colourImage = cvQueryFrame( capture );

    if( colourImage==null ) break;

    //If this is the first time, initialize the images.
    if(first)
    {
    difference = colourImage.clone();
    temp = colourImage.clone();  

    cvConvertScale(colourImage, movingAverage, 1.0, 0.0);
first = false;
    }       

    //else, make a running average of the motion.
    else
    {

    cvRunningAvg(colourImage, movingAverage, 0.020, null);
    }


    //Convert the scale of the moving average.
    cvConvertScale(movingAverage,temp, 1.0, 0.0);

    //Minus the current frame from the moving average.
    cvAbsDiff(colourImage, temp, difference);


    //Convert the image to grayscale.
    cvCvtColor(difference,greyImage,CV_RGB2GRAY);

    //Convert the image to black and white.
    cvThreshold(greyImage, greyImage, 70, 255, CV_THRESH_BINARY);

    //Dilate and erode to get people blobs
    cvDilate(greyImage, greyImage, null, 18);

    cvErode(greyImage, greyImage, null, 10);


    CvSeq contour=new  CvSeq();
    CvMemStorage storage=CvMemStorage.create();
    cvFindContours(greyImage, storage, contour, Loader.sizeof(CvContour.class), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);

    System.out.println(contour.total());

0 个答案:

没有答案