0

I am doing a few basic tutorial on OpenCV. However on this: "https://docs.opencv.org/master/d4/d14/tutorial_windows_visual_studio_image_watch.html" tutorial I am running into problems.

Here is my code:

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv)
{
    char* imageName = argv[1];

    Mat image;
    image = imread(imageName, IMREAD_COLOR);

    if (argc != 2 || !image.data);
    {
        return -1;
    }

    Mat gray_image;
    cvtColor(image, gray_image, COLOR_BGR2GRAY);

    imwrite("C:\OpenCV-test-imgs", gray_image);

    namedWindow(imageName, WINDOW_AUTOSIZE);
    namedWindow("Gray image", WINDOW_AUTOSIZE);

    imshow(imageName, image);
    imshow("Gray image", gray_image);

    waitKey(0);

    return(0);
}

It is basically the same as in the tutorial. I am expecting one or two windows to pop up showing me the two images of the cat. except I'm getting the error :

The program '[14300] image-watch-demo.exe' has exited with code -1 (0xffffffff).

What am I doing wrong here? Should I make a folder containing an image? And if so where should this folder be place and how should it be called.

I'm sorry if this is a dumb quest, I am a beginner to OpenCV and coding/visual studio in general.

Thanks in advance

Bartrae
  • 37
  • 1
  • 8
  • What command line arguments did you use to run the program? There is an `if` that causes the program to return `-1` if you don't provide an image filename or it can't be read. – walnut Mar 18 '20 at 09:45
  • 1
    If you are new to C++, I suggest that you don't start with OpenCV, but with [a good introduction to the language](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) first. – walnut Mar 18 '20 at 09:47
  • The code that is posted is all that I used. What exactly is an command line argument and how to I use it? – Bartrae Mar 18 '20 at 09:48
  • Command line arguments are the options passed to a program when you start it. See [this question](https://stackoverflow.com/questions/298708) for how to add them in Visual Studio (might be outdated though, I don't use Visual Studio). Command line arguments are a very fundamental thing. Again I suggest that you start with the basics before jumping into a library like OpenCV. The tutorials for it will assume that you understand the language. – walnut Mar 18 '20 at 09:53
  • Thank you, I will definitely look into those beginner books in that linked post. I have got the following line in the command arguments now "C:\OpenCV-test-imgs" Is that a step in the right direction? – Bartrae Mar 18 '20 at 10:06

0 Answers0