0

I'm trying to read an image using OpenCV, where I did the following:

input_image = imread(argv[1], IMREAD_UNCHANGED);
    if(input_image.empty())
    {
        cout<<"Image cannot be read";
        return -1;
    }

I'm using Xcode 6.4, and would like to pass two arguments, one for the input image and another for the output image.

So, I did the following in order to pass the argument:

Product --> Scheme --> Edit Scheme...

And, under Arguments, added two arguments: image1.png and image2.png.

I had only image1.png, which I added to the directory containing main.cpp. But, when I try to run the program, the input image seems not to be read, since the above if-statement evaluates to true, and I get the error message.

Why is that? What could I be doing wrong?

Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • Did you try printing `argv[1]`? Also, if the executables are generated somewhere else than where the source file is that might be the reason too.. – Baris Demiray Aug 19 '15 at 15:46
  • The files need to be in the application's "working directory", which is not the same as the source directory. There's a setting for it in your project settings. – molbdnilo Aug 19 '15 at 15:54
  • @molbdnilo I'm really new to this. Is there a reference you recommend for doing that? – Simplicity Aug 19 '15 at 15:59
  • Have a look [here](http://stackoverflow.com/a/31342428/5008845). Most likely you're not passing the correct path. You can try using the full path just to see if you can load the image – Miki Aug 19 '15 at 16:04
  • @Simplicity XCode's builtin manual is usually pretty good. It's in the "Help" menu. (I won't recommend googling "xcode working directory" as the results are rubbish, but there's loads of introductions online.) – molbdnilo Aug 19 '15 at 16:04
  • @Miki I tried the full-path, but didn't work – Simplicity Aug 19 '15 at 16:14
  • 1
    just to narrow down possibilities, try putting the full path in the code as `Mat image = imread("path_to_image");` This should work – Miki Aug 19 '15 at 16:17
  • @Mike Yes, having the full path directly in the code made the program work just fine – Simplicity Aug 19 '15 at 17:08
  • 1
    Well, actually if your image _can_ be loaded, you just need to look where to put input arguments in your IDE (which I dont know). In VS it would be under "debugger" properties. – Miki Aug 19 '15 at 17:20
  • @Miki I tried to enter the full path again as arguments, and it worked just fine! I think the main issue was the ordering of how the arguments were set. Thanks a lot for your support – Simplicity Aug 19 '15 at 17:22

0 Answers0