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.
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.