-1
int main ( int argc, char** argv )
{
    cout << "OpenCV Automatic Number Plate Recognition\n";
    char* filename;
    Mat input_image;
    //Check if user specify image to process
    if(argc >= 2 )
    {
        filename= argv[1];
        //load image  in gray level
        input_image=imread(filename,1);
    }else{
        printf("Use:\n\t%s image\n",argv[0]);
        return 0;
    }        

    string filename_whithoutExt=getFilename(filename);

This is code , the code run without error , but always go here and return 0

        printf("Use:\n\t%s image\n",argv[0]);
        return 0;

Why its not getting the images which are there to process

Edit

When i give the my folder test to process it give the following runtime error :

enter image description here

It run with the argv < 2 mean that it run the else condition , when i goto the configuration setting -> debugging -> commandline argument -> .\test test folder contain images

New to C++ and VS

Rocket
  • 553
  • 8
  • 31
  • 2
    How do you run the program? – NPE Sep 07 '13 at 10:55
  • how do you run this program? – 4pie0 Sep 07 '13 at 10:55
  • Through the visual studio , by pressing the f5 – Rocket Sep 07 '13 at 10:59
  • 1
    You have to set the command line arguments in VS. Or in other words, what were you *expecting* the program to do? – Kerrek SB Sep 07 '13 at 11:02
  • @KerrekSB I am expecting to take the images from folder test or from the project and take them as input – Rocket Sep 07 '13 at 11:03
  • try to debug the program with F10 so you can see what really happens and you are loading a BGR image and not a GRAY you have to put a 0 @ imread instead of 1, I think your fileName isn't correct but you should check it you self ;-) – Engine Sep 07 '13 at 11:04
  • So how do you expect the program to take images from the folder `test` when your code doesn't do that? It looks for `argv[1]` if available. If not, it exits. – Mats Petersson Sep 07 '13 at 11:07
  • @MatsPetersson But how to set the argv[1] in configuration properties -> debugging -> command argument , What to write their ? the name of the folder ? – Rocket Sep 07 '13 at 11:09
  • @Engine I think you didn't actually look at the code he posted. It's clear that his command line is not meeting his expectations (that is, the expectations required by code, not him... I suspect his if clause is just wrong) so his application terminates early. Type of image being displayed couldn't possibly be a factor and `imread()` is clearly never being called. – mah Sep 07 '13 at 11:10
  • Your CURRENT code looks like it's only reading ONE file, the one in `argv[1]`. To read files from a directory, you will have to write some code that iterates through the given directory. I would start by adding the name of ONE file to your command line options and see if that loads the image correctly. Then look for a previous question on here that explains "how to find files in a directory". – Mats Petersson Sep 07 '13 at 11:17
  • well actually the argc should be >= 2 and that it, the question get the right fileName at argv[1] – Engine Sep 07 '13 at 11:17
  • Rather than answering one by one , i edit my question – Rocket Sep 07 '13 at 11:25

1 Answers1

3

how do you run this program?

if your program is called with no arguments or with a single argument i.e:

./myprogram

or ./myprogram img1

it will end here

printf("Use:\n\t%s image\n",argv[0]);

It will enter first condition only if there are 2 or more arguments, i.e:

./myprogram img1 img2

You can specify arguments to be called in project (in IDE) or run it from terminal/console.

Passing command line arguments in Visual Studio 2010?


You said in comments:

I am expecting to take the images from folder test or from the project and take them as input

but it is in contradiction what you are actually doing. If you want to process files you can do it without checking parameters of the program invocations (it is unclear why do you need them and what you want to achieve).

At the moment try from the commandline ./myprogram img1 img2 with img1 being correct name of one of the files. This will try to execute imread(). Alternatively specify img1, img2 in IDE, how to do it you can find in the link provided.

Community
  • 1
  • 1
4pie0
  • 29,204
  • 9
  • 82
  • 118
  • Should i write the name of the folder in configuration properties -> debugging ? – Rocket Sep 07 '13 at 11:07
  • where do you have images? in some folder on disk? – 4pie0 Sep 07 '13 at 11:11
  • 1
    @Ahmad -- you should stop asking questions for a moment and instead answer questions others have given you... specifically what command line you are passing (or at least want to pass to) your program. If helping people understand your expectations like this, they can give you useful responses. – mah Sep 07 '13 at 11:12