OpenCV

javadoc

The OpenCV Service is a library of vision functions.  
Some of the functions are

  • Face detection 
  • Fast Lucas Kanade optical tracking
  • Background forground separation
  • Motion detection
  • Color segmentation

The OpenCV Service has several dependencies, so it will need to be installed before it is used.  You may install it on the Runtime panel.  Highlight the OpenCV service right-click -> install.  A restart is necessary, after installing new services.

The same can be achieved programmatically with the following line of Python

runtime.upgrade("org.myrobotlab.service.OpenCV")

Next you can create start a new OpenCV service by right clicking -> start

Starting a new service can be done programmatically with the following line of Python
 
runtime.createAndStart("opencv", "OpenCV")
 
Many of the functions in OpenCV are implemented as pipeline filters in MRL.  That is a filter can run, and the output of one can be connected to the input of another.  Not all filters are capable of "pipelining"
 
How to Add an OpenCV Filter.
Below shows the steps to add the PyramidDown filter:
Step 1 - select from the available filter
Step 2 - is press the arrow button to move it into the pipeline
Step 3 - is to give it a unique name
 
Python :
 

opencv.addFilter("nameOfMyFilter","PyramidDown")

 
 
How to Modify an OpenCV Filter
Some filters have configuration which can be changed.  You must highlight the filter your interested in, and further configuration may up.  Below is the Canny filter low & high threshold and an aperture size which can be changed.
 
Python:
 
opencv.setFilterCFG("canny","aperture", 1)
 
 
How to Remove an OpenCV Filter
Just highlight and press the left arrow button to remove a filter from the pipeline
 
 
Here are a variety of filters in MRL:
The ever popular face detect

LKOpticalTrack
Lucas Kanade optical tracking will track a selected corner through the video stream.  Load this filter, find a good feature and click the mouse on it.  It will set a point where the mouse was click, as the image moves, the point will move with the object selected.
 
References:
 

Canny
The Canny filter is used for detecting edges in a video stream.  This can be useful in object segmentation.
The function finds the edges on the input image and marks them in the output image edges using the Canny algorithm. The smallest value between lowThreshold and highThreshold is used for edge linking, the largest value is used to find the initial segments of strong edges.
 
Variables
  • apertureSize - aperture parameter for the Sobel operator 
  • lowThreshold - lower threshold on minimal amount of pixels required for edge linking
  • highThreshold - upper threshold on max amount of pixels required for edge linking
 
Python
 
opencv.addFilter("canny","Canny")
opencv.setDisplayFilter("canny")
myfilter = opencv.getFilter("canny") 
myfilter.apertureSize = 3
myfilter.lowThreshold = 10.0
myfilter.highThreshold = 200.0
 
References
 
 
GoodFeaturesToTrack
 
This filter will find prominent corners in a video stream.  After these points are gathered, tracking can be done with the same set of points.  LKOpticalTrack may use this method to initialize a set of good tracking point.
 
References:
 
Flood fill
 
Good Features
 
And InRange which filters on Hue Saturation and Value.
 
Many of the filters output positional points, which in turn can be consumed by other services in MRL. For example a pan / tilt kit with servos can track the point in Face Detect or LKOptical Track.
 
The addtion or removal of filters can be controlled through the Python script in MRL, such that when a motion appears, a program could remove the motion filter and set an LKOptical tracking point to track new motion.
 
References :

Not all cameras work with OpenCV - here is a list of supported cameras from willowgarage

http://opencv.willowgarage.com/wiki/Welcome/OS