繁体   English   中英

opencv c++ 将ipl更改为mat累加

[英]opencv c++ change ipl to mat accumulate

我试图将代码 ipl 更改为 mat

但失败了

我使用 opencv 4.1.2

此示例使用 opencv 2.4.13

https://jadeshin.tistory.com/entry/cvAcc에-의한-배경-영상-계산

我不能用ipl

所以我改变了

 #include <opencv2\opencv.hpp>
 #include <opencv2\highgui\highgui.hpp>
 #include <opencv2\core\mat.hpp>
 #include <opencv2\imgproc.hpp>
 #include <iostream>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture cap("ball.avi");
    if (!cap.isOpened())
    {
            cout << "file not found." << endl;
            return 0;
    }
    Mat image;
    Size size = Size((int)CAP_PROP_FRAME_WIDTH, (int)CAP_PROP_FRAME_HEIGHT);
    Mat grayImage(size, CV_8UC1);
    Mat sumImage(size, CV_32FC1);
    sumImage.setTo(Scalar::all(0));
    int nFrameCount = 0;
    for (;;)
    {
            cap.read(image);
            if (image.empty())
            {
                    cout << "could'nt capture" << endl;
                    break;
            }

            cvtColor(image, grayImage, COLOR_BGR2GRAY);
            accumulate(grayImage, sumImage, NULL); //here is error
            imshow("grayImage", grayImage); 
            char chKey = waitKey(50);
            if (chKey == 27)
                    break;
            nFrameCount++;
    }
    convertScaleAbs(sumImage, sumImage, 1.0 / nFrameCount);
    imwrite("ballBkg.jpg", sumImage);
    destroyAllWindows();
    return 0;
}

编译没有错,但执行有错

我也试过,抓住

但也失败了

积累有什么问题?

C++ 版本的累加void accumulate(InputArray src, InputOutputArray dst, InputArray mask=noArray() )

您正在传递 NULL 而不是noArray() 所以就这样做:

accumulate(grayImage, sumImage);  


 cv::noArray() is an empty Mat not NULL.

编辑 :

也变

Size size = Size((int)CAP_PROP_FRAME_WIDTH, (int)CAP_PROP_FRAME_HEIGHT);

Size size = Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH), (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM