Ask Your Question

GUI for OpenCv with visual studio

asked 2016-03-31 11:22:07 -0500

bthooni gravatar image

updated 2016-04-01 03:16:53 -0500


I have implemented a code using C++ visual studio 2013, with external library: boost and opencv.

Now I'm trying to make a simple graphical user interface for the OpenCv with visual studio. The GUI is:

  1. The user enters a text and this text then saved in a variable..
  2. And when the user press "start" button, the system starts calling the functions.

Can we implement it with highgui? Or we need other tools?

Any suggestions for other tools would be appreciated. Thanks in advance.!

image description

edit retag flag offensive close merge delete


take a look at @pklab 's page

sturkmen gravatar imagesturkmen ( 2016-04-03 15:25:39 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-04-05 13:05:08 -0500

Guyygarty gravatar image

updated 2016-09-08 15:14:01 -0500

Visual studio provides tools to make forms in C++ but, starting with VS2012, they have made it difficult - they want you to make forms in C#, or VB not in C++.

A good tutorial on how to make a windows forms application using Visual C++ 2013 is given here

Basically you need your application to be a CLR application, rather than a console. You can then add GUI forms to it and call OpenCV from them. I have written several such applications and can help if you have more specific questions on interfacing OpenCV with CLR forms.



Here is an example. The form frmImaging has a buttons called cmdLoad and cmdSave and a textbox txtFileName. In the associated cpp file I have:

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

cv::Mat image //global mat file for storing the image. It is accessible by all GUI callbacks in this file. 

//callback for cmdLoad button - loads image into Mat
System::Void frmImaging::cmdLoad_Click(System::Object^  sender, System::EventArgs^  e) 
//Get filename

    if( openFileDialog1->ShowDialog()!=::DialogResult::OK)

    char FileName[200];

//load image    
//display image 
        imshow("Display Window",image);

//callback of cmdSave button - save image
System::Void frmImaging::cmdSave_Click(System::Object^  sender, System::EventArgs^  e) 
        // get filename from GUI
    char FileName[200];

    imwrite(FileName, image);

edit flag offensive delete link more


I would love to know more about this. I've created my OpenCV code and works perfectly while showing using 'imshow'. I've created a separate project for the C++ form as suggested. But I have no idea how to link the opencv code with the CLR application's form gui.

AnotherRandomGuy gravatar imageAnotherRandomGuy ( 2016-09-04 09:19:39 -0500 )edit

you can just write the OpenCV code into the GUI control's callback function. I'll add an example to the answer, as there is no room in comments.

Guyygarty gravatar imageGuyygarty ( 2016-09-08 15:04:12 -0500 )edit

@Guyygarty: Do we have to copy this code in "MyForm.cpp" (where we add those lines of codes) or "MyForm.h" (where we have int main)?

srt92 gravatar imagesrt92 ( 2017-09-28 09:31:10 -0500 )edit

I try to avoid having any code (other than the main form constructor) in the .h file. The code above goes in MyForm.cpp

Guyygarty gravatar imageGuyygarty ( 2017-12-27 08:35:21 -0500 )edit

answered 2016-04-01 03:19:46 -0500

Well if you built OpenCV with QT support the highgui windows do provide everything you will need. But it still remains very basic!

If you want a more advanced interface, you will need some other GUI interface!

edit flag offensive delete link more


The main problem is : when i want to implement interface in VS (visual stdio) the subsystem should be "windows" And to run code of opencv in VS the subsystem should be "console " For that i need some way to join project console type for opencv with windows type for GUI .. And we use QT platform for c++ and link it with opencv but how we can use opencv with interface at the same time ? It give a lot of errors .

bthooni gravatar imagebthooni ( 2016-04-03 15:13:28 -0500 )edit

i test this code " " but it get a lot of errors

bthooni gravatar imagebthooni ( 2016-04-03 15:18:39 -0500 )edit

what is your OpenCV version? you could try OpenCV 3.1 documentation if you compiled OpenCV with QT support

sturkmen gravatar imagesturkmen ( 2016-04-03 17:06:21 -0500 )edit

my OpenCV version is 2.4.11

bthooni gravatar imagebthooni ( 2016-04-03 17:15:15 -0500 )edit

Without the actual errors, by updating your topic, it will be quite difficult to tell the reason of the errors.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-04 02:01:09 -0500 )edit

Question Tools



Asked: 2016-03-31 11:22:07 -0500

Seen: 5,435 times

Last updated: Sep 08 '16