-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This guide presumes some experience with CDP Studio. For new users it is recommended to first watch some tutorial videos of CDP Studio, like creating Raspberry LED Blinker to get general idea how to use Studio.
This project is a small demo of using OpenCV computer vision library with CDP Studio. It includes two projects:
- ComputerVision - contains pre-configured CDP Application that is ready to run
- ComputerVisionLib - contains the C++ code that uses OpenCV
Inside ComputerVisionLib two components are defined:
- ColorTracking - displays image from webcam and tracks coordinates of a specific color
- Camera - displays image from webcam and uses ColorFilter to filter a specific color
This project depends on OpenCV:
- Download OpenCV from http://download.cdpstudio.com/libs/opencv/3.4.1
- Follow the Using OpenCV with CDP Studio guide
- Make sure OpenCV is downloaded and imported as described under Prerequisites
- Open both ComputerVision and ComputerVisionLib projects with CDP Studio
- First build the library project ComputerVisionLib. Then run the ComputerVision system
By default the system includes only the ColorTracking component. If successful, one should see three windows:
- Original Image - displays image from webcam. A red circle marks the tracked color (if found on image).
- Trackbars - here it is possible to specify the color to track in HSV (hue, saturation, value) encoding.
- Thresholded Image - highlights matching part of webcam image as a white area. Useful when specifying correct values in Trackbars window.
Next right click on the ComputerVision project and select Connect. Then open the ColorTracking component. There you will see in Signals table xCoord
and yCoord
CDP Signals. They mark the location of the tracked color. This is the place of the red circle in the Original Image window. The signals could be used to write code that depends on tracking an object of specific color using webcam.
To see the implementation of ColorTracking component, go to Code Mode and open ComputerVisionLib -> Sources -> ColorTracking.cpp.
To test the Camera component, first stop the ColorTracking application. Then go to Configure Mode and delete the ColorTracking component from ComputerVisionApp.
After that:
- Add the Camera component listed under ComputerVisionLib in the Resource tree.
- Click on the Camera component and add a ColorFilter from Resource tree
- In the ColorFilters table edit the columns for added ColorFilter. Use HMIN, HMAX, SMIN, SMAX, VMIN and VMAX to set desired color in HSV (hue, saturation, value) encoding.
- Run the system
Next a ColorFilter window should appear. If the entire image is only white or only black, try adjusting the HSV values. It is possible to connect to the system and change these values during runtime.
To see the implementation of Camera component, go to Code Mode and open ComputerVisionLib -> Sources -> Camera.cpp. Similarly ColorFilter is defined in ColorFilter.cpp.