Skip to content


OpenCV input output example

OpenCV has a nice simple cross platform GUI. You can display images, read from keyboard and mouse, input some number using sliders, write on screen, etc. In this post I will show you an example code that I developed that achieves all these things. Because I used cmake, this code can be compiled and run in either Windows or Ubuntu. Feel free to use this code for your next projects. I commented it thoroughly to make it easy to understand.
Remember that you need to have OpenCV and cmake already installed in your machine. If you are using Ubuntu, you can read the installation instructions from here.
OK, the first step is to download and extract the example that I made. You can download it from here.
Go to the command line, navigate to where the code is and execute the following code:

cmake .
make

This will generate the executable. Now run it:

./ioSample

I created a small area on the lower part of the display where I write the actual values of three different inputs that you can use in OpenCV. If you move the mouse around the image, its position will be updated. Also, if you change the slider, the new value will appear. You can also press any key and it will report which was the last key that has been pressed.

I also implemented an inverse function for showing pixel level access to the input image. This can be achieved by just pressing the ‘i’ key.

Finally, if you click on any part of the image, the background color will change to the color of the clicked pixel.

Posted in Image Processing, Open Source, Programming.


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. huhmaster says

    Thank you Sebastian. OpenCV and Qt are my fav. libraries and you have done some nice work on them. Kudos to you.

  2. samontab says

    Thanks huhmaster, Qt and OpenCV are awesome projects indeed.

  3. wan says

    how to capture video?i’m working for my final year project to create virtual gaming system



Some HTML is OK

or, reply to this post via trackback.