0

I've been learning openCV from scratch as an amateur and I'm getting on quite well, but the one thing I don't understand is how to load an image using this. For example the basic code is:

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main( int argc, char** argv ) {

    Mat img = imread( argv[1], -1 );
    if( img.empty() ) return -1;
    namedWindow( "Example2", WINDOW_AUTOSIZE );
    imshow( "Example2", img );
    waitKey( 0 );

    return 0;
}`

I think I understand that argc is the number of arguments and argv[i] is the particular argument - like argv[0] is the main proc. I don't see how this helps me, though. Say I have an image located at C:\image.jpg - how would I load this using that function? Many thanks for the help, I have looked at some similar questions but I still don't understand.

Galik
  • 47,303
  • 4
  • 80
  • 117
Mike Miller
  • 253
  • 6
  • 18
  • 3
    If you call: `yourapp.exe "C:\image.jpg"` argv[1] will be the path. – Borgleader Oct 22 '14 at 13:08
  • @Borgleader I'm doing this through Visual Studio 2012, how do I change the .exe file? I have a folder where I save my source files - do you mean that? – Mike Miller Oct 22 '14 at 13:18
  • 1
    You need to back up and learn about the command line. You maybe have never used the command line before. Open a Command Prompt window and start your program that way. Pass an argument to it. Once you understand what the comment line is, then it's time to move on to how to specify a command line in the IDE. But don't start with the IDE. – David Heffernan Oct 22 '14 at 13:29
  • @DavidHeffernan Ah, OK. I've been learning solely through VS and codeblocks, not tried through the command line. Many thanks. – Mike Miller Oct 22 '14 at 13:30
  • 1
    You can do this within visual studio as well. Under your solution properties there is an option to add command line arguments. Then when you build and run it inside visual studio, it'll run those arguments. You will still need to use the command line to run it outside of visual studio though – Connor H Oct 22 '14 at 14:37
  • @ConnorH Fantastic, that's a lot easier for me. Many thanks. – Mike Miller Oct 22 '14 at 15:11

0 Answers0