簡體   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