Author: Job van Dieten < job.1994@gmail.com >
Maintainer: Jordi Pages < jordi.pages@pal-robotics.com >
Support: tiago-support@pal-robotics.com
Source: https://github.com/pal-robotics/tiago_tutorials.git
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Corner Detection (C++)
Description: There are two corner detector algorithms often used in the OpenCV library, the Shi-Tomasi and Harris functions. In this simple tutorial you will see how changing two parameters can affect the corner detectionKeywords: OpenCV
Tutorial Level: BEGINNER
Next Tutorial: Find Keypoints
Contents
Purpose
This tutorial aims to show how to use the Shi-Tomasi and Harris corner detection functions changing two simple parameters.
Pre-Requisites
First, make sure that the tutorials are properly installed along with the TIAGo simulation, as shown in the Tutorials Installation Section.
Execution
In order to execute the demo first open a couple of consoles and source the public simulation workspace
cd /tiago_public_ws/ source ./devel/setup.bash
In the first console run the following simulation of TIAGo
roslaunch tiago_gazebo tiago_gazebo.launch public_sim:=true end_effector:=pal-gripper world:=tutorial_office gzpose:="-x -3.73 -y -3.83 -z 0.001 -R 0.0 -P 0.0 -Y -1.57"
The robot will be spawned in front of a shelve.
In the second console run the Corner Detection node as follows
rosrun tiago_opencv_tutorial corner_detection
Two windows will show up, one with the corners detected by the Harris function and one with the Shi-Tomasi one.
Sliders are provided in order to tune the paramteres of each corner detector.
Concepts & Code
The difference in the Shi-Tomasi and Harris functions is slight, however it becomes more apparent when their equation is shown.
Firstly, a corner in the OpenCV Mat structure is defined as a region in which the intensity varies greatly in all directions. The most important feature in the two methods is the scoring function R. The Harris method defines the scoring function as
R = v * w - k(v + w)^2
as represented in the source code as
where v and w are the Eigen values of the matrix containing the image. In this case the difference in t Shi-Tomasi proposed a different cost function, namely
R = min(v,w)}
which simply states that if the eigen values are higher than a certain threshold value, the region is considered to be a corner. The resulting corners detected are slightly better, and more suited for some applications such as object tracking.