1

I am new to C++ and am trying to go through some OpenCV tutorials I found online. I produced the code exactly as it was found in Visual Studio 2013 and was able to run the code properly. However, I keep getting an error:

(Press Retry to debug the application) Debug Error!

Program: ...rface_Basics\x64\Debug\OpenCV_Basics_CPP_Interface_Basics.exe

R6025 - pure virtual function call

(Press Retry to debug the application)

I was reading about pure virtual functions and it sounded like you had to at least declare a virtual function for this error to occur which has only lead to more confusion. Below is my code:

#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;
        }
    }
}

I have tried removing arguments from the main function and going through the debug process provided in the quote above. However, it just calls this crt0msg.c file and highlights case 1 of section #ifdef _DEBUG.

Any help resolving this issue would be much appreciated.

Evan Smith
  • 23
  • 5
  • 1
    For the record, same bug on Ubuntu 14.04 with Opencv 3.0.0. Seems to be taken into account, see link in @DeJaVo 's answer, lets wait for next release. – kebs Jul 16 '15 at 10:20

2 Answers2

2

Using a static or global Mat causing the issue.

I found the problem, in

>    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;
>    }

Source:http://code.opencv.org/issues/3355

this is an open defect in OpenCV (not fixed yet). Try to update your open CV to the latest version , the defect record mention a partial fix that maybe help you overcome this issue.

DeJaVo
  • 3,091
  • 2
  • 17
  • 32
  • Thank you for the link! I found that simply moving the Mat calls into the main function cleared up the problem. – Evan Smith Jul 15 '15 at 18:00
  • Referring to your link, it also appears that there is work being done with regards the code for the matrix.cpp and ocl.cpp files in an attempt to actually resolve the issue. While the current patch didn't work for me, following the comments on the following link should lead to a final solution. date.https://github.com/Itseez/opencv/pull/4136 – Evan Smith Jul 15 '15 at 18:34
1
    Mat image;
    Mat processedImage;

That global declaration is the problem. Call

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

before the

    return 0;

in the main. This problem seems to be associated with recent opencv3.0 (I had used both alpha and beta, and the RC1 versions and they didn't give any such errors).