Ask Your Question
0

jpg does not show

asked 2013-04-08 14:39:54 -0500

Julien gravatar image

Hello

The following code does not work with this image : http://dl.free.fr/vahKqrTqs while it works successfully with the cow image from this page : http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.html?highlight=laplacian

Any idea ?

cv::Mat img = cv::imread("R0010054.JPG");

if(img.empty())
{
    return -1;
}

cv::imshow("image", img);

Thanks Julien

edit retag flag offensive close merge delete

Comments

Did you write the correct name (case sensitive)? And did you add a cv::waitKey(); after your cv::imshow() ?

Guanta gravatar imageGuanta ( 2013-04-08 15:31:19 -0500 )edit

Hum, sorry, I did not put the whole code, it was obvious to me that there was a waitkey at the end. Sorry for that... In fact, a window appears but it does not contain something that looks like the original image. See "capture" here : http://dl.free.fr/nAe3YDU0W

Julien gravatar imageJulien ( 2013-04-08 16:16:59 -0500 )edit

btw: I don't like dl.free.fr it has many javascript-foo - I won't load that...

Guanta gravatar imageGuanta ( 2013-04-08 16:30:29 -0500 )edit

ok, I will find something else. Stay tuned !

Julien gravatar imageJulien ( 2013-04-08 16:46:12 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-08 15:37:25 -0500

updated 2013-04-08 15:49:25 -0500

Basically like Guanta just suggested, place a waitKey command

cv::Mat img = cv::imread("C:/test/R0010054.JPG"); //it is better to use absolute paths first

if(img.empty())
{
     cout << "Image not loaded";
     return -1; //i guess this isn't throwed, add a print statement none the less
}

cv::imshow("image", img);
waitKey(0); //time added here counts in milliseconds --> needed for processing

behind the imshow. It makes sure that the draw and update function of the window are properly called before closing down the window. Place a 0 if you want the window only to close when pressing a key.

Some more tips

  • Always add debug output, it will show you where it goes wrong
  • When loading of images doesn't work, try with absolute path first, then experiment with relative paths. Sometimes a relative path isn't recognized due to faulty environment variables.
edit flag offensive delete link more

Comments

1

@StevenPuttemans: afaik waitKey(0) == waitKey()

Guanta gravatar imageGuanta ( 2013-04-08 16:05:56 -0500 )edit

Hoppa, learned something new :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-08 16:43:21 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-04-08 14:39:54 -0500

Seen: 244 times

Last updated: Apr 08 '13