Skip to content

A simple (but naive) example of OpenCV / GtK cross-platform application written in C++ running on Raspberry PI, Windows, Mac OS X and Linux

License

Notifications You must be signed in to change notification settings

raspberry-cpp-tutorials/gtk-opencv-simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Gtk / OpenCV application in C++

C++, OpenCV and Gtk are a nice triplet to build applications that run on a Raspberry PI, taking images from the camera, process them, display them and have an unlimited user interface. In this example I'm showing a straight-forward way to display camera captures into a full screen window. In the next example, gtk-opencv-patterns, I amend some of the shortcomings of this too naive method. I hope these two examples can help you through the boring problems you need to solve before reaching the place where you can have fun.

I'm using the following technical stack:

  • Raspberry Pi - The ultimate goal is to launch the application on it.
  • CMake - This is the needed ingredient to make your code buildable on most of the platforms. It also exports your project to Xcode, VisualStudio, Eclipse and a long list of others, so you will be able to choose your preferred IDE.
  • Mac OS X, Ubuntu, Windows - Where you can write and test your application.
  • C++ - Python is fashionable, young, efficient and well supported by Raspberry folks. But I happen to like C++ more. If Python is your thing, then stop reading.
  • OpenCV - One very widely used open source (hence the Open) computer vision (hence the CV) library.
  • Gtkmm, which is the C++ oriented port of Gtk - Although OpenCV lets you display images on screen, it is somewhat limited when interacting with the user. Being easily compatible, Gtk / Gtkmm are a great complement to OpenCV for building real user interfaces around computer vision applications.

The branches structure

In the Wiki articles I'm explaining the code quite in detail. To help the exposition order, I split the code into multiple steps:

  • Step1 branch contains the code for step 1.
  • Step2 branch contains step 2.
  • Etc.
  • Master branch contains the final code, all steps together.

Cross-platform application

An important element is to be able to build and test your project in your preferred desktop computer or notebook. Raspberry Pi is meant to be an embedded system platform, and it is an amazing one. Still, it lacks the right keyboard, mouse, monitor or amount of memory required to be a comfortable as a development tool.

You find in Wiki the detailed instructions to install a working development environment in the three major operative systems:

Last but not least:

The project's folder structure

There are several great articles that discuss about the best folder structure for a project built with CMake:

Projects having multiple executables and libraries need one folder per module, and each module should have multiple folders according to the type of file or resource. In the case of a simple application written in one single module, producing one single executable, I'm just having one root folder, called src and, in it, one folder for each type of file - sources, headers and resources:

.gitignore        <-- Ignore xcode, codeb, build folders.
/src              <-- All sources are here
   CMakeList.txt  <--- The CMake configuration file.
      /cpp        <----- Contains the C++ source files.
      /hpp        <----- Contains the C++ header files.
      /res        <----- Contains resource files.
/build            <-- Contains the temporary build files. 
                      Not under version control
/xcode            <-- Contains the XCode project.
                      Not under version control.
/codeb            <-- Contains the Code::Blocks project. 
                      Not under version control. 

About

A simple (but naive) example of OpenCV / GtK cross-platform application written in C++ running on Raspberry PI, Windows, Mac OS X and Linux

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published