【问题标题】:Debug assertion Failed Opencv Function调试断言失败的 Opencv 函数
【发布时间】:2016-03-19 11:23:52
【问题描述】:

我的代码有问题。我尝试在 Visual Studio 2015 上使用 opencv 3.0 执行背景减法。函数 main 是:

int main()
{

//altrimento creo la finestra
    Mat image;
    Mat fgMaskMOG2;
    Rect mr;
    Ptr<BackgroundSubtractor> pKNN;
    //imposto la sequenza delle immagini
    std::string path = "D:\\ProjectFile\\CoreSaw_DataFusion\\Dataset\\Persona posa oggetto\\gray-%06d.jpg";
    VideoCapture sequence(path);

    //se non è aperto esco con codice di errore
    if (!sequence.isOpened())
    {
        cerr << "Failed to open Image Sequence!\n" << endl;
        return 1;
    }
    for (;;)
    {
        //scelgo l'immagine seguente
        sequence >> image;
        resize(image, image, Size(400,400));
        //ridimensiono l'immagine perchè permette una miglior rilevazione
        //se vuota finisco la sequenza
        if (image.empty())
        {
            cout << "End of Sequence" << endl;
            break;
        }
        try
        {
            apply_BackgroundSubstraction(image, fgMaskMOG2);
        }
        catch (Exception exc)
        {
            cerr << "Main: " << exc.msg << endl;
        }
        waitKey(1); 
    }
    return 0;
}

而我的功能是:

void apply_BackgroundSubstraction(Mat image, Mat fgMask)
{

    vector< vector<Point> > contours;
    try
    {
        namedWindow("Display window");// Create a window for display.
        Ptr<BackgroundSubtractor> pKNN = createBackgroundSubtractorKNN(216, 3500.0, true);
        pKNN->apply(image, fgMask); //applico l'algoritmo di background substraction 
        Mat contourImg = fgMask.clone();
        findContours(contourImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
        vector<vector< Point> >::iterator itc = contours.begin();
        while (itc != contours.end()) {

            Rect rect = boundingRect(Mat(*itc));
            rectangle(image, rect, CV_RGB(255, 0, 0));
            itc++;
        }
        imshow("Display window", fgMask);
        imshow("Blob", image);
    }
    catch (Exception exc)
    {
        cerr << "apply_BackgroundSubstraction: " << exc.msg << endl;
    }
}

当这个函数结束时我有这个错误

DEBUG ASSERTION FAILDED : IS BLOCK_TYPE_VALID(HEADER->BLOCK_USE)

你能帮帮我吗?

【问题讨论】:

  • opencv 是使用 Visual Studio 14 2015 构建的吗?
  • 是的,我在 Visual Studio 14 2015 中使用 cmake

标签: c++ debugging opencv visual-studio-2015


【解决方案1】:

这不是错误的答案,但您应该在 main 函数中创建 createBackgroundSubtractorKNN 并将其传递给您的 apply_BackgroundSubstraction 函数。

我的测试代码是用 VS 2015 编译的,运行良好。

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include<opencv2/objdetect/objdetect.hpp>
#include "opencv2/video/background_segm.hpp"
#include<iostream>

using namespace cv;
using namespace std;

void apply_BackgroundSubstraction( Ptr<BackgroundSubtractor> pKNN, Mat image, Mat fgMask)
{

    vector< vector<Point> > contours;
    try
    {
        namedWindow("Display window");// Create a window for display.
        pKNN->apply(image, fgMask); //applico l'algoritmo di background substraction
        Mat contourImg = fgMask.clone();
        findContours(contourImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
        vector<vector< Point> >::iterator itc = contours.begin();
        while (itc != contours.end()) {

            Rect rect = boundingRect(Mat(*itc));
            rectangle(image, rect, CV_RGB(255, 0, 0));
            itc++;
        }
        imshow("Display window", fgMask);
        imshow("Blob", image);
    }
    catch (Exception exc)
    {
        cout << "apply_BackgroundSubstraction: " << exc.msg << endl;
    }
}

int main( int argc, char** argv )
{
    char* filename = argc >= 2 ? argv[1] : (char*)"768x576.avi";
    VideoCapture capture( filename );

    Mat frame,output;
    Ptr<BackgroundSubtractor> pKNN = createBackgroundSubtractorKNN(216, 3500.0, true);

    while(true)
    {
        capture.read(frame);
        if (!frame.data)
            return 0;

        apply_BackgroundSubstraction( pKNN, frame, output);

        if(waitKey(1)==27)
        {
            break;
        }
    }
    return 0;
}

【讨论】:

  • 好的,谢谢我尝试,但我有同样的错误:(问题是函数 apply_BackgroundSubstraction 结束时!:(
  • 我认为你的 VS 配置有问题。
猜你喜欢
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
  • 2016-11-13
  • 2014-02-10
相关资源
最近更新 更多