Skip to content
Karmo7 edited this page Jun 26, 2018 · 9 revisions

CDP Studio logo

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.

Introduction

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

Prerequisites

This project depends on OpenCV:

Running the project

ColorTracking component

  1. Make sure OpenCV is downloaded and imported as described under Prerequisites
  2. Open both ComputerVision and ComputerVisionLib projects with CDP Studio
  3. 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.

Camera component

To test the Camera component, first stop the ColorTracking application. Then go to Configure Mode and delete the ColorTracking component from ComputerVisionApp.

After that:

  1. Add the Camera component listed under ComputerVisionLib in the Resource tree.
  2. Click on the Camera component and add a ColorFilter from Resource tree
  3. 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.
  4. 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.

Clone this wiki locally