OpenCV 2.2 VS2010 - Get "Read Access Violations" in very simple code

I just installed OpenCV 2.2 and Visual C ++ 2010 and configured it. I do not get compilation errors, but I run this code. I get this error.

Unhandled exception at 0x6c2f22f2 (msvcr100.dll) in Es_CornerDetector.exe: 0xC0000005: access violation reading location 0x002a1000. 

code:

 #include "opencv/highgui.h" #include "opencv2/features2d/features2d.hpp" int main(int argc, char** argv) { cv::SurfFeatureDetector detector; detector.create("SURF"); } 

I really don’t understand what could be the reason.

Update:

Using the "detector.create ()" function may be wrong, so I tried something else, but I got another error (always when I try to access the "detector"):

 First-chance exception at 0x67608ef4 in Es_CornerDetector.exe: 0xC0000005: Access violation writing location 0x02655008. Unhandled exception at 0x67608ef4 in Es_CornerDetector.exe: 0xC0000005: Access violation writing location 0x02655008. 

Alternative code:

 #include "opencv\cv.h" #include "opencv\highgui.h" #include "opencv2\features2d\features2d.hpp" #include <vector> #include <iostream> int main() { IplImage* img_temp = cvLoadImage("img.jpg"); cv::Mat img(img_temp); if(img.empty()==1) { std::cout << "Can't load the image.." << endl; getchar(); return -1; } cv::SurfFeatureDetector detector; vector<cv::KeyPoint> keypoints; detector.detect(img,keypoints); return 0; } 

Update 2

I get the same error on two different systems with both VS2010 and VS2008, and also, if I try to run the descriptor_extractor_matcher.cpp code example, which can be found in. \ OpenCV2.2 \ samples \ cpp \ descriptor_extractor_matcher.cpp

attempted OpenCV 2.3.1 (both binary and compiled):

Wow, new exotic bug:

 Run-Time Check Failure #2 - Stack around the variable 'keypoints' was corrupted. 

I'm going to give up ...

+4
source share
9 answers

I had the same problem, and it turned out that the directory with opencv binaries on my system path incorrectly led to the wrong directory containing the vc10 or vc9 opencv binaries. See if there is something like this problem. Hope this helps.

+4
source

You need to make sure that the following “Additional Dependencies” under “Properties-> Attachments-Inserts” refer to the correct OpenCV libraries with debugger support.

i.e.

 C:\OpenCV2.2\lib\opencv_calib3d220d.lib C:\OpenCV2.2\lib\opencv_core220d.lib C:\OpenCV2.2\lib\opencv_features2d220d.lib C:\OpenCV2.2\lib\opencv_highgui220d.lib C:\OpenCV2.2\lib\opencv_imgproc220d.lib 

instead

 C:\OpenCV2.2\lib\opencv_calib3d220.lib C:\OpenCV2.2\lib\opencv_core220.lib C:\OpenCV2.2\lib\opencv_features2d220.lib C:\OpenCV2.2\lib\opencv_highgui220.lib C:\OpenCV2.2\lib\opencv_imgproc220.lib 
+3
source

Try to get OpenCV 2.3.1 superpack here . If this still causes problems, I would try compiling OpenCV from the source using CMake . Follow this guide to create OpenCV from source.

Besides the obvious problem with the fact that the DLL is not in the same directory as the executable, it looks like there might be a mismatch between the compiled binary architecture (i.e. 32-bit / VS2005 and 64-bit / VS2010) and one that you're using.

Hope this will be helpful!

EDIT: Can you try compiling and running this code (this works fine on my system)? Make sure you use version 2.3.1 for this.

 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp> #include <vector> using namespace std; using namespace cv; int main(int argc, char* argv[]) { Mat image = imread("yourimage.jpg", 0); Ptr<FeatureDetector> detector = FeatureDetector::create("FAST"); vector<KeyPoint> points; detector->detect(image, points); Mat imageColor; cvtColor(image, imageColor, CV_GRAY2BGR); drawKeypoints(imageColor, points, imageColor, Scalar(255, 0, 0), DrawMatchesFlags::DRAW_OVER_OUTIMG); imshow("imageColor", imageColor); waitKey(); return 0; } 

Can you also post a link to the image where you are trying to run the function detection? Also, how do you create your project in Visual Studio?

+1
source

the solution is to use libraries with the suffix 'd', such as opencv_core244d.lib, for debugging and use regular versions such as "opencv_core244.lib" for release. It just works. Good luck.

+1
source

Be sure to enable opencv_nonfreeXXXX.lib, as well as other libs (e.g. opencv_coreXXXXXd) in the project dependency settings. Then you SHOULD explicitly declare this line of code:

initModule_nonfree ();

in the source code before performing any operation with SURF or SIFT. They are no longer free! Praised the day realizing this.

The error message displayed does not give an idea that this is a potential problem.

+1
source

In VS, look at t to see which DLL for opencv loads. Make sure the dll is the one you expect.

You can also use ProcMon, which is part of the SysInternals package, to see what is loading.

0
source

I changed the use of MFC as "MFC in a shared DLL" and it fixed this problem for me.

0
source

You are probably linking the OpenCV libraries with the standard Visual Studio configuration ( All configurations ) instead of the Debug and Release configurations separately.

To change the configuration, select:

  • Project Properties → Configuration (upper left corner) → Select Debug
  • Project Properties → Linker → Input → Additional Dependencies

Make sure you link the OpenCV debug libraries (see final d , for example opencv_calib3d220 d .lib):

 C:\OpenCV_Path\lib\opencv_calib3d220d.lib C:\OpenCV_Path\lib\opencv_core220d.lib C:\OpenCV_Path\lib\opencv_features2d220d.lib C:\OpenCV_Path\lib\opencv_highgui220d.lib C:\OpenCV_Path\lib\opencv_imgproc220d.lib 
  • Project Properties → Configuration (upper left corner) → Select Release
    1. Project Properties → Linker → Input → Additional Dependencies

Make sure tahat you are linking OpenCV release libraries (without final d ):

 C:\OpenCV_Path\lib\opencv_calib3d220.lib C:\OpenCV_Path\lib\opencv_core220.lib C:\OpenCV_Path\lib\opencv_features2d220.lib C:\OpenCV_Path\lib\opencv_highgui220.lib C:\OpenCV_Path\lib\opencv_imgproc220.lib 

Hope this helps you.

0
source

Make sure that the DLL and d.dll that you specified are exactly the ones you specified in opensv forlder "d.dll" and ".dll" (for Release and Debug mode). Sometimes we follow a textbook and do not verify that the names they give match the names of our archives. (They may use a different version of Opencv, and the names will change something).

0
source

Source: https://habr.com/ru/post/1383108/


All Articles