{"id":69,"date":"2010-04-24T23:00:12","date_gmt":"2010-04-24T13:00:12","guid":{"rendered":"http:\/\/www.samontab.com\/web\/?p=69"},"modified":"2021-03-03T09:55:30","modified_gmt":"2021-03-02T22:55:30","slug":"opencv-input-output-example","status":"publish","type":"post","link":"https:\/\/www.samontab.com\/web\/2010\/04\/opencv-input-output-example\/","title":{"rendered":"OpenCV input output example"},"content":{"rendered":"<p>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.<br \/>\nRemember 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 <a href=\"http:\/\/www.samontab.com\/web\/2010\/04\/installing-opencv-2-1-in-ubuntu\/\">here<\/a>.<br \/>\nOK, the first step is to download and extract the example that I made. You can download it from <a href=\"http:\/\/www.samontab.com\/web\/files\/ioexample.zip\">here<\/a>.<br \/>\nGo to the command line, navigate to where the code is and execute the following code:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncmake .\r\nmake\r\n<\/pre>\n<p>This will generate the executable. Now run it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n.\/ioSample\r\n<\/pre>\n<p><a href=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-Image.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-Image-245x300.png\" alt=\"\" title=\"Screenshot-Image\" width=\"245\" height=\"300\" class=\"alignnone size-medium wp-image-70\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-Image-245x300.png 245w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-Image.png 522w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><\/a><\/p>\n<p>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.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot2-245x300.png\" alt=\"\" title=\"Screenshot\" width=\"245\" height=\"300\" class=\"alignnone size-medium wp-image-71\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot2-245x300.png 245w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot2.png 521w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><\/a><\/p>\n<p>I also implemented an inverse function for showing pixel level access to the input image. This can be achieved by just pressing the &#8216;i&#8217; key.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-1-246x300.png\" alt=\"\" title=\"Screenshot-1\" width=\"246\" height=\"300\" class=\"alignnone size-medium wp-image-72\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-1-246x300.png 246w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-1.png 521w\" sizes=\"auto, (max-width: 246px) 100vw, 246px\" \/><\/a><\/p>\n<p>Finally, if you click on any part of the image, the background color will change to the color of the clicked pixel.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-2-245x300.png\" alt=\"\" title=\"Screenshot-2\" width=\"245\" height=\"300\" class=\"alignnone size-medium wp-image-73\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-2-245x300.png 245w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2010\/04\/Screenshot-2.png 522w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,30,4],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-open-source","category-opencv","category-programming"],"_links":{"self":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}