Ask Your Question
0

GUI for OpenCv with visual studio

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

bthooni gravatar image

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

Hi

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

Comments

take a look at @pklab 's page

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

2 answers

Sort by ยป oldest newest most voted
1

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

Guyygarty gravatar image

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

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.

guy

Edit

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(System::String::IsNullOrEmpty(openFileDialog1->InitialDirectory))
        openFileDialog1->InitialDirectory=txtDir->Text;

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

    txtFilename->Text=openFileDialog1->FileName;
    char FileName[200];
    sprintf(FileName,"%s",openFileDialog1->FileName);

//load image    
    image=imread(FileName,CV_LOAD_IMAGE_ANYDEPTH);
//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];
    sprintf(FileName,"%s",txtFilename->Text);


    imwrite(FileName, image);

}
edit flag offensive delete link more

Comments

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 -0600 )edit
1

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 -0600 )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 -0600 )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 -0600 )edit
1

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

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

Comments

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 -0600 )edit

i test this code " http://docs.opencv.org/2.4/modules/hi... " but it get a lot of errors

bthooni gravatar imagebthooni ( 2016-04-03 15:18:39 -0600 )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 -0600 )edit

my OpenCV version is 2.4.11

bthooni gravatar imagebthooni ( 2016-04-03 17:15:15 -0600 )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 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 5,907 times

Last updated: Sep 08 '16