相关文章推荐
潇洒的茶壶  ·  vscode ...·  2 天前    · 
无聊的生姜  ·  cv2.imread 和PIL ...·  2 天前    · 
近视的砖头  ·  javacv函数关系opencv ...·  昨天    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm a starter in OpenCV. My programming environment is VC++ Express 2010 + OpenCV 2.4.2 + Win 7 64 bit.

I use purely 32bit configuration in my VC++ and Path.

I type in the following code:

#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
using namespace cv;
int main(int argc, char** argv) {
    char* imgPath = "logo.png";
    Mat img = imread(imgPath);
    namedWindow( "Example1", WINDOW_AUTOSIZE);
    imshow("Example1", img);
    waitKey(0);
    return 0;

Then I compile and run. It does come up with a window (but without picture) but then gave me this (a runtime error?)

Unhandled exception at 0x770515de in Helloworld2.exe: Microsoft C++ exception: cv::Exception at memory location 0x001ef038..

Then I change the imread into cvLoadImage and it works without any errors.

Can someone tell me what's wrong?

I have tried the code you have given. It works perfectly fine with my installation of OpenCV.

However I am getting a warning at the line:

char* imgPath = "logo.png";
main.cpp:6:21: warning: deprecated conversion from string constant to 'char*' [-

Wwrite-strings]

Which i think is nothing serious to make the code crash, however it might be the problem in your case, as I am not using VC++ to compile.

What you can try to check if this is the issue is to replace imgPath with directly the string, so the code will now be like

Mat img = imread("logo.png"); 

I also got this issue, but I fixed it with the following. The point is using absolute path other than relative path, and change "\" with "/" in the file path.

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
int main() {
    cv::Mat image = cv::imread("D:/projects/test/Debug/1.jpg");
    if (image.empty()) {
        return 0;
    cv::namedWindow("my image");
    cv::imshow("my image", image);
    cv::waitKey(5000);
    return 1;

But there is an implicit conversion from const char * to string. As masad noted, this conversion is deprecated, so it is very compiler dependent.

As cvLoadImage works for you, it seems that you should change your code to something like this:

#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include <string>
using namespace cv;
int main(int argc, char** argv) {
    std::string imgPath("logo.png");
    Mat img = imread(imgPath);
    namedWindow( "Example1", WINDOW_AUTOSIZE);
    imshow("Example1", img);
    waitKey(0);
    return 0;

There has been some problems with C++ interface in Visual Studio, but you may try to see if it works for you.

I had the same problem and I came across Installing OpenCV 2.4.3 in Visual C++ 2010 Express and it mentions to use the updated set of libraries *d.lib when adding dependencies for the Linker. I tried it and the C++ interface worked. Not sure if this is the case in general. I am using OpenCV 2.4 and Visual Studio 2010 on a 64 bit Windows machine.

I got the similar problem with you. When I use the imread function, the program crash with system error message: opencv_debug.exe 中的 0x0036299f 处未处理的异常: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突

Then I change the imread into cvLoadImage and it works without any errors.

Finally, I fix the problem, it comes because I used VS2008 project with VS2010 compiled dll.

Here is my story.

Environment: VS2008 + opencv2.4.7

First, I just follow the link http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html, and compile the my test project.

But, When I run my test project, the system error dialog tells me that I lost MSVCP100D.dll MSVCR100D.dll. So I download the two dll, the dll lost problem is solved, but the problem is crash on run time.

Notice that ahead link, it says:

it means that, in opencv2.4.7, they only provide dlls which compiled in vs2010 or vs2012, not vs2008.

When I compiling vs2008 project with dlls which compiled by vs2010, I get the wired problem.

How can I fix this problem?

  • use the older opencv version such as opencv2.3, this version contains the vs2008 compiled dll.

  • compile the opencv by yourself.

  • I have noticed that your environment is: VC++ Express 2010 + OpenCV 2.4.2 + Win 7 64 bit. Be sure OPENCV_DIR is set right.

    setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc10

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.