Author: Job van Dieten < email@example.com >
Maintainer: Sara Cooper < firstname.lastname@example.org >
|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 detection
Tutorial Level: BEGINNER
Next Tutorial: Find ArucoBoard
First, make sure that the tutorials are properly installed along with the ARI simulation, as shown in the Tutorials Installation Section.
In order to execute the demo first open a couple of consoles and source the public simulation workspace
cd ~/ari_public_ws source ./devel/setup.bash
In the first console run the following simulation of ARI
$ roslaunch ari_gazebo ari_gazebo.launch public_sim:=true 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 ari_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 parameteres 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.