Ask Your Question
0

problem of using class cv :: Mat in the environment C + + CLR

asked 2014-02-08 10:03:08 -0600

Hi!

cv::Mat img = imread("test.jpg");
if (img.empty())
// Print ERROR_1 ...

Fails to initialize the object Mat. Method emty () always returns true. Initialize the structure IplImage same file - "test.jpg" not shed any causes. In console applications, class cv :: Mat works fine. IDE: Visual Studio 2010 Professional, NET Framework 4.5 Prompt in what could be the reason?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-02-09 15:30:51 -0600

updated 2014-02-09 19:54:23 -0600

The code i used and it worked for me

include opencv2/highgui/highgui.hpp

include opencv2/core/core.hpp

include iostream

(include the above files and the rest of the code goes down here)

using namespace std;

using namespace cv;

int main()
{


cv::Mat img = imread("left.jpg");

if (img.empty())

{

    cout <<"error" <<endl;

}

else

{

    cout <<"image read" <<endl;

}

return 0;

}

Hope this helps you :)

edit flag offensive delete link more

Comments

1

When you post an answer with code, if you select the code with the mouse and hit Ctrl+k the code will be highlighted properly so it is easier to read and understand by humans. Thank you for your contribution!

Martin Peris gravatar imageMartin Peris ( 2014-02-09 19:56:34 -0600 )edit
0

answered 2014-02-09 19:51:35 -0600

updated 2014-02-09 19:52:23 -0600

You are using a relative path for test.jpg. Are you sure that the image is located where it is supposed to when you run your executable?

You are probably executing your program from a working directory different than what you are expecting.

Just to be sure, you could try to provide imread the absolute path to the image test.jpg

Good luck!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-08 10:03:08 -0600

Seen: 267 times

Last updated: Feb 09 '14