3
  • Im using Opencv 2.3.1 on Visual studio 2010 (vc10)
  • I have configured opencv based on many tutorials and can compile & run C-syntax program like:

#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main ()
{
    IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
    cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
    cvShowImage("display", img );
    cvWaitKey(0);        

    return 0;
}

However, I cannot run the C++ syntax program like

#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std; 

int main(  )
{ 
    namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
    Mat image;
    image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);   

    if(! image.data )                             
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }
    imshow( "Display window", image );                   

    waitKey(0);                                          
    return 0;
}

I got the error messages (in the function calls: namedWindow, imread, imshow)

First-chance exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.

Unhandled exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.

How can I fix this?

6
  • "D:\cat_helmet" is definitely wrong. "D:\\cat_helmet.jpg". Commented Oct 23, 2011 at 9:46
  • The access violation error hit right at the namedWindow() command. And the two ways declaring image file are both OK. I compiled and ran the former piece of code above successfully. Commented Oct 23, 2011 at 13:10
  • Have you placed the opencv_core231.dll and opencv_highgui231.dll's in the run directory, or placed these DLLs in the path, so they can be linked to dynamically? Commented Oct 23, 2011 at 14:58
  • Consider checking our tutorial on how to install/configure OpenCV 2.3 on VS2010: stackoverflow.com/questions/7011238/… Commented Oct 24, 2011 at 23:57
  • @karlphillip: I followed your tutorial several days ago. It is amazing, thanks :) Now, I have moved to Ubuntu 11.10, still using Opencv 2.3 and CAN run the codes correctly. May be the C++ interface of Opencv is still not stable for Windows. Anyone who want to use opencv on ubuntu can see a great tutorial here: ozbots.org/opencv-installation Commented Oct 26, 2011 at 8:04

2 Answers 2

5

You say that you have followed a multitude of guides and tutorials. I've had great success with this one http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/

The thing is that this guy walks you through the 'park' and helps you unravel two major issues whilst setting up OpenCV 2.3.1; one of which is placement of .dll files in your project folder. The other is a missing .dll 'tbb_debug.dll' (the absense of this .dll is considered a bug in OpenCV 2.3.1).

He also provides some decent code-snippets for your to try out (in c++ syntax).

Good luck.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried following the tutorial and now everything works great. Thanks a lot.
@ducnm, Glad I could help. On my study, a multitude of 8 groups 5 people each ventured tries on both OpenCV and OpenFrameworks, and more than 75% had major issues. A guide like the one I posted was just what we had needed back at the beginning of learing about image processing.
0

The above mentioned answers doesn't make sense. I am also facing the same problem. The main reason for this exception is that you are trying to display image (read by imread) which is empty. The main problem in the program is the line

    image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR); 

I think imread function is not behaving the way it is expected. One more thing, while going through the references i came across a following link:

http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)

Here, imread is used via call by reference method. I am not a C++ expert, but i feel it could be the problem.

    int main() 
    {
      std::string imgPath("splash.bmp"); //Add your file name
      Mat img = imread(imgPath);
      namedWindow( "Example1", WINDOW_AUTOSIZE);
      imshow("Example1", img);
      waitKey(0);
      return 0;
    }

This code worked for me. Also, I put the file next to executable to decrease complexity.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.