user667430
user667430

Reputation: 1547

OpenCV let user choose to open image

I am trying to create a simple image processor in opencv. I so far have experimented to open a set image from file with this code.

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("c:/image.jpg");
    if (im.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);
}

As this only allows a set image file to be open, how could i modify it so it allows the user to select an image?

Is this possible or can i only load a set image from file?

Thanks.

Upvotes: 1

Views: 9174

Answers (2)

Barshan Das
Barshan Das

Reputation: 3767

If you want your program to run in console only, let the user to input the path of the image file ( or may be using command line arguments).

If you want to make it GUI application, (some fancy window will show up when you click a "Open File" button ) then you have to learn some GUI programming. Choose some GUI programming tool depending on your platform ( Windows, Linux etc) or go for cross platform ( Give a try to Qt )

Upvotes: 5

Ove
Ove

Reputation: 6317

If you want the user to be able to browse for an image on their computer, you can use the open file dialog box. You can find a sample on MSDN.

Upvotes: 1

Related Questions