Ask Your Question
0

problem with reading image to Mat

asked 2012-12-12 06:57:19 -0600

bee. gravatar image

updated 2012-12-12 07:05:29 -0600

I'm using Visual Studio 2012 with OpenCv 2.4.3 and I don't know if I'm doing sth wrong but I can't do the simplest imread(), because there is a problem with memory I think. Here is the code:

#include <iostream>
#include <string>

#include <imgproc\imgproc.hpp>  
#include <core\core.hpp>        
#include <highgui\highgui.hpp>       


using namespace std;
using namespace cv;

Mat img;

int main(int argc, char *argv[])
{
    img = imread("lena.jpg", 1);
    namedWindow("Lena", CV_WINDOW_AUTOSIZE);
    imshow("Lena", img);
    waitKey();

    return 0;
}

During debuging it stops at imread() and throws exception: Unhandled exception at 0x5B9665AF (msvcr90d.dll) in opencv_test.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

If anyone knows what could be wrong, please help

edit retag flag offensive close merge delete

Comments

Thank you for your responses. I actually fixed it. The problem was in environmental variable path, there was for version vs2008 and next for 2012. When I removed the first one, there was a problem with missing .dll, but there are lots of guides how to managed it. So it works :)

@StevePuttemans: I tried manual debugging, but it alwas stopped at imread() line, it didn't read the picture so the mat object was empty. And I didn't know what to do. These are my first steps with opencv and c++. Anyway it works. Thanks for your answer :)

bee. gravatar imagebee. ( 2012-12-12 08:42:57 -0600 )edit

I don't have OpenCV libraries in PATH. Instead I add needed path in the project settings (Debugging -> Environment), and have menu items in Far Manager, which add needed path to the current session.

What for your case, the DLL name immediately suggests that we have DLL hell curse. Numbers 90 in the name define MSVC version (9.0 is Visual Studio 2008, 10.0 is VS 2010). I recommend you to carefully inspect your PATH variable and clean everything unneeded.

That's a pity that there is no such thing as modules (http://modules.sourceforge.net) in windows.

wl2776 gravatar imagewl2776 ( 2012-12-13 02:02:39 -0600 )edit
1

You are welcome :) Feel free to accept an answer as solution to your problem.

Indeed making sure the path variables are correct, is important, also including the correct libraries in linker settings is essential.

Manually debugging does help situate exactly. If it stops at a function try going step by step through the code and do a dive inside function imread(). It could show you where exact it went wrong.

StevenPuttemans gravatar imageStevenPuttemans ( 2012-12-14 02:19:36 -0600 )edit

Hello bee,

I'm having the exact same problem as this. My picture path is correct but it refuses to show because the imread always returns an empty matrix. Would you mind elaborating on what you meant by "there was for version vs2008 and next for 2012" ?

Double Vision gravatar imageDouble Vision ( 2013-05-12 09:51:49 -0600 )edit

@Double Vision, when linking your libs you can select the vc folder, which is the edition of your visual compiler. It means that you should select vc9 or vc10 for vs2008-2010 but vc11-12 for vs2012 due to more functionality available inside the compiler.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-09 02:33:45 -0600 )edit
1

I encountered the same issue. It turns out I should use the full path of the image file.

smwikipedia gravatar imagesmwikipedia ( 2015-07-22 00:22:28 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2012-12-12 07:34:56 -0600

First of all, if dynamic linking doesn't seem to work try to do some manual debugging.

Step 1: add static path to your image : img = imread("D:/lena.jpg", 1); Make sure that the image is actually there and the extension is actually .jpg and not .jpeg

Step 2: place a debug stop after the imread function and see if actually something is inside the mat object.

Then report back with the results!

edit flag offensive delete link more
0

answered 2015-02-07 03:02:39 -0600

I met the same problem, finally I found my program should use x86 dll and lib files instead of x64. Hope it can help others.

edit flag offensive delete link more
-1

answered 2012-12-12 08:35:26 -0600

Geppertm gravatar image

Try this version.

` #include <opencv.hpp> #include <iostream>

using namespace std; using namespace cv;

int main(int argc, char *argv[]) { Mat img = imread("lena.jpg", 1); namedWindow("Lena", CV_WINDOW_AUTOSIZE); imshow("Lena", img); waitKey();

return 0;

} `

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-12 06:57:19 -0600

Seen: 9,402 times

Last updated: Dec 12 '12