Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 2.2 VS2010 - Get an "Access violation reading" in a very simple code

I just installed OpenCV 2.2 and Visual C++ 2010 and configured it. I don't get compilation errors but running 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 which can be the cause..

Update:

The use of "detector.create()" may be wrong so I tried something different but i get another error (always when I try to access "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 in 2 different system both with VS2010 and VS2008 and also if I try to run the example code descriptor_extractor_matcher.cpp that can be found in ..\OpenCV2.2\samples\cpp\descriptor_extractor_matcher.cpp

OpenCV 2.3.1 attempt (both binaries and compiled):

Wow, new exotic error:

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

I'm about to give up...

like image 832
Mr.G Avatar asked Dec 27 '22 10:12

Mr.G


1 Answers

I had the same problem and figured out that the directory having opencv binaries in my system path was incorrectly led to wrong directory which contains vc10 or vc9 opencv binaries. See if your problem is something like this. Hope this helps.

like image 103
Tae-Sung Shin Avatar answered Mar 04 '23 17:03

Tae-Sung Shin