opencv

I am trying to display a picture saved on my desktop, but after running this code, I am getting the following answer on my linux terminal:

"Image not found or unable to open"

I am not sure what the problem is, since this code seems to have been successfully used by others.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <opencv2/highgui.hpp>
#include <iostream>
 
int main( int argc, const char** argv )
{

     Mat img = imread("/home/user/Desktop/pic.jpg", CV_LOAD_IMAGE_UNCHANGED);

     if (img.empty()) 
     {
          cout << "Error : Image cannot be loaded..!!" << endl;

          return -1;
     }

     namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); 
     imshow("MyWindow", img); 

     waitKey(0);

     destroyWindow("MyWindow"); 

     return 0;
}
Does your /home/user/Desktop directory contain a file named "pic.jpg"?
I doubt that's your actual code:
- your code doesn't compile: missing cv and std namespace qualifiers
- ¿shouldn't the message be «Error : Image cannot be loaded..!!»?

to void stupid filename typos use the tab-complete features of your shell to pass arguments into `argv' (same can be done with rlwrap and std::cin)


PS: your opencv version seems to be ancient: those macros are no more, were replaced by constants inside the namespace
1
2
CV_LOAD_IMAGE_UNCHANGED -> cv::IMREAD_UNCHANGED
CV_WINDOW_AUTOSIZE -> cv::WINDOW_AUTOSIZE
Last edited on
nevermind, I made it work.
All is needed is to add cv:: to all the lines.
Thanks anyway for your help
Topic archived. No new replies allowed.