Ask Your Question

How to debug imread()

asked 2017-06-26 12:41:37 -0500

I try to run the very first project. I have Visual Studio 2015, downloaded opencv-, and want to use ready libraries which are included. I prepared everything as described in Introduction to OpenCV \How to build applications with OpenCV inside the "Microsoft Visual Studio" Win32 console application (Debug mode) was created successfully. I have placed necessary DLL files in the same directory as EXE and placed BMP file in the same directory and into the project directory too. When I run the program, it fails with the code -1

Mat image;

// image = imread(argv[1], IMREAD_COLOR); // Read the file

image = imread("Circle.bmp"); // Read the file

if (! // Check for invalid input
    cout << "Could not open or find the image " << argv[1] << std::endl;
    return -1;

I tried to run with administrator rights, tried non-system directory, tried to run from Visual Studio IDE. How to determine why it can't read this file?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-06-26 15:26:55 -0500

LBerger gravatar image

Using vs 2015 you will need all pdb files, not present in opencv- If you want to debug in opencv source code you have to clone opencv and build opencv using cmake.

About your error now you should give full path and you can use slash instead of backslach. If you are in debug check you link your sorce code with opencv_world320d.lib and you use only opencv_world320d.dll

edit flag offensive delete link more


Thanks for your advice. The first part is what I primarily needed. Now I try to figure out how to do it. In Tutorials, there is a long list of external tools to install, but they write: "Alternatively, you can just download an archived version of the source files from our page on Sourceforge" If I want just

imread() namedWindow() imshow() waitKey()

can I do it without additional installations using only Visual Studio, cmake, and that source files?

ya_ocv_user gravatar imageya_ocv_user ( 2017-06-27 02:02:35 -0500 )edit

As to the second part, I tried full path with the minimum of directories "C:\Temp\Circle.bmp", slashes, escaped backslashes. No use. I looked through other questions about this issue. The most probable reason is problems with Unicode. I noticed rubbish captions when tried to create windows. imread() simply can't understand the file name so can't find it. What is opencv_world320d.dll? Do you mean that I should install version 3 instead of opencv- I tried the latest release, but it looks quite rudimentary yet. Did they integrate all various functionality into the single file?

ya_ocv_user gravatar imageya_ocv_user ( 2017-06-27 02:04:49 -0500 )edit

If you want to build opencv you need only cmake. nothing more. Main advantage to build opencv is you will have an opencv version optimized for your computer. If you want to use cuda (with a compatible graphics card) you will need cuda compiler.

About file name Did you dave your source fle in unicode?It could be a problem. Do you copy and paste file name in source code? It could be a problem write it using keyboard (ascii character) You can try to load opencv/samples/data/lena.jpg too

LBerger gravatar imageLBerger ( 2017-06-27 02:44:53 -0500 )edit

The program works correctly in Debug x64. That's already something. Will try the other modes by analogy. Debug x86 outputs error 0xc000007b even before the first function.

ya_ocv_user gravatar imageya_ocv_user ( 2017-06-27 14:26:30 -0500 )edit

Debug x86 there is no dll for x86 in opencv- If you want to use x86 you have to build opencv using cmake

LBerger gravatar imageLBerger ( 2017-06-27 14:35:29 -0500 )edit

In my installation it is present opencv\build\x86\vc14\bin\opencv_core2413d.dll The timestamp is different from x64. Looks like it's OK. Others are present too. ... Oops. I have copied from the different directory. Now have replaced and this version works too.

ya_ocv_user gravatar imageya_ocv_user ( 2017-06-28 00:31:56 -0500 )edit

Question Tools

1 follower


Asked: 2017-06-26 12:41:37 -0500

Seen: 1,117 times

Last updated: Jun 26 '17