1

我是 C++ 新手,正在尝试阅读我在网上找到的一些 OpenCV 教程。我完全按照在 Visual Studio 2013 中找到的代码生成了代码,并且能够正确运行代码。但是,我不断收到错误消息:

(按重试调试应用程序)调试错误!

程序:...rface_Basics\x64\Debug\OpenCV_Basics_CPP_Interface_Basics.exe

R6025 - 纯虚函数调用

(按重试调试应用程序)

我正在阅读有关纯虚函数的内容,听起来您至少必须声明一个虚函数才能发生此错误,这只会导致更多混乱。下面是我的代码:

#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

//main functions
void processImage();
void displayGraphics();

//images
Mat image;
Mat processedImage;

int main(int argc, char *argv[])
{
    //create a window
    namedWindow("Image");
    namedWindow("ProcessedImage");

    //load the image
    if (argc > 1)
        image = imread(argv[1]);
    else
        image = imread("lena.jpg");
    if (image.empty())
        exit(1);

    processImage();
    displayGraphics();

    waitKey(0);

    return 0;
}

void displayGraphics()
{
    //display both images
    imshow("Image", image);
    imshow("ProcessedImage", processedImage);
}

void processImage()
{
    int x, y;
    Vec3b pixel;
    unsigned char R, G, B;
    processedImage = image.clone();

    for (y = 0; y < processedImage.rows; y++)
    {
        for (x = 0; x < processedImage.cols; x++)
        {
            // Get the pixel at (x,y)
            pixel = processedImage.at<Vec3b>(y, x);
            // Get the separate colors
            B = pixel[0];
            G = pixel[1];
            R = pixel[2];
            // Assign the complement of each color
            pixel[0] = 255 - B;
            pixel[1] = 255 - G;
            pixel[2] = 255 - R;
            // Write the pixel back to the image
            processedImage.at<Vec3b>(y, x) = pixel;
        }
    }
}

我尝试从主函数中删除参数并完成上面引用中提供的调试过程。但是,它只是调用这个 crt0msg.c 文件并突出显示 #ifdef _DEBUG 部分的案例 1。

任何解决此问题的帮助将不胜感激。

4

2 回答 2

2

使用导致问题的静态或全局 Mat。

我发现了问题,在

>    MatAllocator* Mat::getStdAllocator() {
>    static StdMatAllocator allocator;//it's static. but mat's destructor need >it. so when that's have a static or global mat, can not be guaranteed this >allocator's destructor after that static or global mat.
>    return allocator;
>    }

来源:http ://code.opencv.org/issues/3355

这是 OpenCV 中的一个开放缺陷(尚未修复)。尝试将您打开的 CV 更新到最新版本,缺陷记录中提到了可能会帮助您克服此问题的部分修复。

于 2015-07-14T05:57:54.213 回答
1
    Mat image;
    Mat processedImage;

全球声明就是问题所在。称呼

    image.release();
    processedImage.release(); 

之前

    return 0;

在主要。这个问题似乎与最近的 opencv3.0 有关(我使用了 alpha 和 beta,以及 RC1 版本,他们没有给出任何此类错误)。

于 2015-07-31T21:23:33.213 回答