Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create GUI with "Select file" dialog in cpp, OpenCV

is there any way to enable user to select file manually using GUI in my cpp console application with OpenCV? I've made some research but found no solution for such trivial task so far...

Thanks in advance, JP

like image 362
user2208392 Avatar asked Apr 09 '13 04:04

user2208392


2 Answers

For this, you have to add any available gui library and handle the gui part with that keeping the image processing part to opnecv. ( For example, you can try Qt )

like image 81
Barshan Das Avatar answered Sep 30 '22 11:09

Barshan Das


If you want to a simple file open dialog in Ubuntu, you can do this:

FILE *in;
if (!(in = popen(
        "zenity  --title=\"Select an image\" --file-selection",
        "r"))) {
    return 1;
}

char buff[512];
string selectFile = "";
while (fgets(buff, sizeof(buff), in) != NULL) {
    selectFile += buff;
}
pclose(in);

//remove the "\n"
selectFile.erase(std::remove(selectFile.begin(), selectFile.end(), '\n'),
            selectFile.end());

// path + filename + format
Mat image = imread(selectFile);
like image 23
Paulo Ferreira Avatar answered Sep 30 '22 11:09

Paulo Ferreira