Ask Your Question
0

Basic script to input / output img doesn't work

asked 2016-02-27 13:58:34 -0600

I compiled the script at the bottom, and ran it with

./a.out baboon.pgm

It ran without any errors, but nothing was output, whereas I expected a file named L2.pgm to be output. What am I doing wrong?

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"

using namespace cv;

int main(int argc, char ** argv){
        if (argc != 1){
                return -1;
        }
        Mat image;
        image = imread(argv[1]);
        imwrite("/home/makes/practice/L2.pgm", image );
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-02-27 23:45:42 -0600

berak gravatar image

this has nothing to do with opencv, it is all about argc/argv argument parsing

the problem is here:

    if (argc != 1){
             return -1;
     }

your program will always return -1, if you actually give it an argument (because argc will be 2 then, remember, argv[0] is the program name) . so , change it to, e.g. :

    if (argc < 2) {
             cerr << "this program expects a path to an image !" << endl;
             return -1;
     }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-27 13:58:34 -0600

Seen: 102 times

Last updated: Feb 27 '16