Using OpenCV for Color Tracking
Introduction
This purpose of this example is to show how CDP Studio integrates with OpenCV and how to use the OpenCV functions from CDPComponent C++ code in CDP Studio, the independent automation software for open PC-based real-time distributed control systems.
This project uses the OpenCV computer vision library to read camera image and filter out or track a specific color.
Prerequisites
This project depends on OpenCV. Follow the Importing OpenCV to CDP Studio guide. Make sure to download the OpenCV binaries and complete the File -> Import Library... step.
How to Run the Example
To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the library project and select Build, then right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information.
Project Overview
This example includes:
- A library project containing one component:
- ColorTracking - displays image from webcam and tracks coordinates of a specific color.
- A system project containing a pre-configured CDP Application that is ready to run.
After running the project, 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 select the ComputerVision project and 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.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.