svn repository web references are replaced with links to git

This commit is contained in:
Andrey Kamaev
2012-08-07 13:29:43 +04:00
parent b061d4847f
commit 639bbec44a
66 changed files with 1180 additions and 1305 deletions

View File

@@ -15,7 +15,7 @@ In this tutorial you will learn how to:
* Use :surf_descriptor_extractor:`SurfDescriptorExtractor<>` and its function :descriptor_extractor:`compute<>` to perform the required calculations.
* Use a :brute_force_matcher:`BruteForceMatcher<>` to match the features vector
* Use the function :draw_matches:`drawMatches<>` to draw the detected matches.
Theory
======
@@ -23,9 +23,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include <stdio.h>
#include <iostream>
@@ -45,7 +45,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ return -1; }
@@ -74,7 +74,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
//-- Draw matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
//-- Show detected matches
imshow("Matches", img_matches );
@@ -93,9 +93,9 @@ Explanation
Result
======
#. Here is the result after applying the BruteForce matcher between the two original images:
.. image:: images/Feature_Description_BruteForce_Result.jpg
:align: center
:height: 200pt

View File

@@ -14,7 +14,7 @@ In this tutorial you will learn how to:
* Use the :surf_feature_detector:`SurfFeatureDetector<>` and its function :feature_detector_detect:`detect<>` to perform the detection process
* Use the function :draw_keypoints:`drawKeypoints<>` to draw the detected keypoints
Theory
======
@@ -22,14 +22,14 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/features2D/SURF_detector.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_detector.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
@@ -44,7 +44,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
@@ -61,8 +61,8 @@ This tutorial code's is shown lines below. You can also download it from `here <
//-- Draw keypoints
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
//-- Show detected (drawn) keypoints
imshow("Keypoints 1", img_keypoints_1 );
@@ -82,9 +82,9 @@ Explanation
Result
======
#. Here is the result of the feature detection applied to the first image:
.. image:: images/Feature_Detection_Result_a.jpg
:align: center
:height: 125pt
@@ -92,6 +92,6 @@ Result
#. And here is the result for the second image:
.. image:: images/Feature_Detection_Result_b.jpg
:align: center
:height: 200pt
:align: center
:height: 200pt

View File

@@ -19,9 +19,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include <stdio.h>
#include <iostream>
@@ -41,7 +41,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
@@ -79,7 +79,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
@@ -87,13 +87,13 @@ This tutorial code's is shown lines below. You can also download it from `here <
for( int i = 0; i < descriptors_1.rows; i++ )
{ if( matches[i].distance < 2*min_dist )
{ good_matches.push_back( matches[i]); }
}
}
//-- Draw only "good" matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Show detected matches
imshow( "Good Matches", img_matches );
@@ -115,9 +115,9 @@ Explanation
Result
======
#. Here is the result of the feature detection applied to the first image:
.. image:: images/Featur_FlannMatcher_Result.jpg
:align: center
:height: 250pt

View File

@@ -12,7 +12,7 @@ In this tutorial you will learn how to:
* Use the function :find_homography:`findHomography<>` to find the transform between matched keypoints.
* Use the function :perspective_transform:`perspectiveTransform<>` to map the points.
Theory
======
@@ -20,9 +20,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include <stdio.h>
#include <iostream>
@@ -43,7 +43,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
Mat img_object = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_scene = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_object.data || !img_scene.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
@@ -81,21 +81,21 @@ This tutorial code's is shown lines below. You can also download it from `here <
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_object.rows; i++ )
{ if( matches[i].distance < 3*min_dist )
{ good_matches.push_back( matches[i]); }
}
}
Mat img_matches;
drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Localize the object
//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;
@@ -103,7 +103,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
}
Mat H = findHomography( obj, scene, CV_RANSAC );
@@ -143,6 +143,6 @@ Result
#. And here is the result for the detected object (highlighted in green)
.. image:: images/Feature_Homography_Result.jpg
:align: center
:height: 200pt
:align: center
:height: 200pt

View File

@@ -19,9 +19,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
@@ -55,7 +55,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
/// Create Trackbar to set the number of corners
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo);
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo);
imshow( source_window, src );
@@ -72,7 +72,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
void goodFeaturesToTrack_Demo( int, void* )
{
if( maxCorners < 1 ) { maxCorners = 1; }
/// Parameters for Shi-Tomasi algorithm
vector<Point2f> corners;
double qualityLevel = 0.01;
@@ -86,7 +86,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
copy = src.clone();
/// Apply corner detection
goodFeaturesToTrack( src_gray,
goodFeaturesToTrack( src_gray,
corners,
maxCorners,
qualityLevel,
@@ -95,18 +95,18 @@ This tutorial code's is shown lines below. You can also download it from `here <
blockSize,
useHarrisDetector,
k );
/// Draw corners detected
cout<<"** Number of corners detected: "<<corners.size()<<endl;
int r = 4;
for( int i = 0; i < corners.size(); i++ )
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),
rng.uniform(0,255)), -1, 8, 0 ); }
/// Show what you got
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
imshow( source_window, copy );
imshow( source_window, copy );
/// Set the neeed parameters to find the refined corners
Size winSize = Size( 5, 5 );
@@ -118,7 +118,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
/// Write them down
for( int i = 0; i < corners.size(); i++ )
{ cout<<" -- Refined Corner ["<<i<<"] ("<<corners[i].x<<","<<corners[i].y<<")"<<endl; }
{ cout<<" -- Refined Corner ["<<i<<"] ("<<corners[i].x<<","<<corners[i].y<<")"<<endl; }
}
@@ -129,10 +129,10 @@ Result
======
.. image:: images/Corner_Subpixeles_Original_Image.jpg
:align: center
:align: center
Here is the result:
.. image:: images/Corner_Subpixeles_Result.jpg
:align: center
:align: center

View File

@@ -11,7 +11,7 @@ In this tutorial you will learn how to:
.. container:: enumeratevisibleitemswithsquare
* Use the OpenCV function :corner_eigenvals_and_vecs:`cornerEigenValsAndVecs <>` to find the eigenvalues and eigenvectors to determine if a pixel is a corner.
* Use the OpenCV function :corner_min_eigenval:`cornerMinEigenVal <>` to find the minimum eigenvalues for corner detection.
* Use the OpenCV function :corner_min_eigenval:`cornerMinEigenVal <>` to find the minimum eigenvalues for corner detection.
* To implement our own version of the Harris detector as well as the Shi-Tomasi detector, by using the two functions above.
Theory
@@ -20,9 +20,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
@@ -34,9 +34,9 @@ This tutorial code's is shown lines below. You can also download it from `here <
using namespace std;
/// Global variables
Mat src, src_gray;
Mat src, src_gray;
Mat myHarris_dst; Mat myHarris_copy; Mat Mc;
Mat myShiTomasi_dst; Mat myShiTomasi_copy;
Mat myShiTomasi_dst; Mat myShiTomasi_copy;
int myShiTomasi_qualityLevel = 50;
int myHarris_qualityLevel = 50;
@@ -70,7 +70,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
cornerEigenValsAndVecs( src_gray, myHarris_dst, blockSize, apertureSize, BORDER_DEFAULT );
/* calculate Mc */
/* calculate Mc */
for( int j = 0; j < src_gray.rows; j++ )
{ for( int i = 0; i < src_gray.cols; i++ )
{
@@ -81,25 +81,25 @@ This tutorial code's is shown lines below. You can also download it from `here <
}
minMaxLoc( Mc, &myHarris_minVal, &myHarris_maxVal, 0, 0, Mat() );
/* Create Window and Trackbar */
namedWindow( myHarris_window, CV_WINDOW_AUTOSIZE );
createTrackbar( " Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel,
myHarris_function );
createTrackbar( " Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel,
myHarris_function );
myHarris_function( 0, 0 );
/// My Shi-Tomasi -- Using cornerMinEigenVal
myShiTomasi_dst = Mat::zeros( src_gray.size(), CV_32FC1 );
myShiTomasi_dst = Mat::zeros( src_gray.size(), CV_32FC1 );
cornerMinEigenVal( src_gray, myShiTomasi_dst, blockSize, apertureSize, BORDER_DEFAULT );
minMaxLoc( myShiTomasi_dst, &myShiTomasi_minVal, &myShiTomasi_maxVal, 0, 0, Mat() );
/* Create Window and Trackbar */
namedWindow( myShiTomasi_window, CV_WINDOW_AUTOSIZE );
createTrackbar( " Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel,
myShiTomasi_function );
namedWindow( myShiTomasi_window, CV_WINDOW_AUTOSIZE );
createTrackbar( " Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel,
myShiTomasi_function );
myShiTomasi_function( 0, 0 );
waitKey(0);
return(0);
}
@@ -114,9 +114,9 @@ This tutorial code's is shown lines below. You can also download it from `here <
for( int j = 0; j < src_gray.rows; j++ )
{ for( int i = 0; i < src_gray.cols; i++ )
{
if( myShiTomasi_dst.at<float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal -
if( myShiTomasi_dst.at<float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal -
myShiTomasi_minVal )*myShiTomasi_qualityLevel/max_qualityLevel )
{ circle( myShiTomasi_copy, Point(i,j), 4, Scalar( rng.uniform(0,255),
{ circle( myShiTomasi_copy, Point(i,j), 4, Scalar( rng.uniform(0,255),
rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
}
}
@@ -135,9 +135,9 @@ This tutorial code's is shown lines below. You can also download it from `here <
{
if( Mc.at<float>(j,i) > myHarris_minVal + ( myHarris_maxVal - myHarris_minVal )
*myHarris_qualityLevel/max_qualityLevel )
{ circle( myHarris_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255),
{ circle( myHarris_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255),
rng.uniform(0,255) ), -1, 8, 0 ); }
}
}
}
imshow( myHarris_window, myHarris_copy );
}
@@ -151,9 +151,9 @@ Result
======
.. image:: images/My_Harris_corner_detector_Result.jpg
:align: center
:align: center
.. image:: images/My_Shi_Tomasi_corner_detector_Result.jpg
:align: center
:align: center

View File

@@ -18,9 +18,9 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
@@ -56,7 +56,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
/// Create Trackbar to set the number of corners
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );
imshow( source_window, src );
@@ -70,10 +70,10 @@ This tutorial code's is shown lines below. You can also download it from `here <
* @function goodFeaturesToTrack_Demo.cpp
* @brief Apply Shi-Tomasi corner detector
*/
void goodFeaturesToTrack_Demo( int, void* )
void goodFeaturesToTrack_Demo( int, void* )
{
if( maxCorners < 1 ) { maxCorners = 1; }
/// Parameters for Shi-Tomasi algorithm
vector<Point2f> corners;
double qualityLevel = 0.01;
@@ -87,7 +87,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
copy = src.clone();
/// Apply corner detection
goodFeaturesToTrack( src_gray,
goodFeaturesToTrack( src_gray,
corners,
maxCorners,
qualityLevel,
@@ -96,18 +96,18 @@ This tutorial code's is shown lines below. You can also download it from `here <
blockSize,
useHarrisDetector,
k );
/// Draw corners detected
cout<<"** Number of corners detected: "<<corners.size()<<endl;
int r = 4;
for( int i = 0; i < corners.size(); i++ )
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),
rng.uniform(0,255)), -1, 8, 0 ); }
/// Show what you got
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
imshow( source_window, copy );
imshow( source_window, copy );
}
Explanation
@@ -117,6 +117,6 @@ Result
======
.. image:: images/Feature_Detection_Result_a.jpg
:align: center
:align: center

View File

@@ -10,7 +10,7 @@ In this tutorial you will learn:
.. container:: enumeratevisibleitemswithsquare
* What features are and why they are important
* What features are and why they are important
* Use the function :corner_harris:`cornerHarris <>` to detect corners using the Harris-Stephens method.
Theory
@@ -56,7 +56,7 @@ How does it work?
.. container:: enumeratevisibleitemswithsquare
* Let's look for corners. Since corners represents a variation in the gradient in the image, we will look for this "variation".
* Let's look for corners. Since corners represents a variation in the gradient in the image, we will look for this "variation".
* Consider a grayscale image :math:`I`. We are going to sweep a window :math:`w(x,y)` (with displacements :math:`u` in the x direction and :math:`v` in the right direction) :math:`I` and will calculate the variation of intensity.
@@ -66,10 +66,10 @@ How does it work?
where:
* :math:`w(x,y)` is the window at position :math:`(x,y)`
* :math:`w(x,y)` is the window at position :math:`(x,y)`
* :math:`I(x,y)` is the intensity at :math:`(x,y)`
* :math:`I(x+u,y+v)` is the intensity at the moved window :math:`(x+u,y+v)`
* Since we are looking for windows with corners, we are looking for windows with a large variation in intensity. Hence, we have to maximize the equation above, specifically the term:
.. math::
@@ -89,36 +89,36 @@ How does it work?
.. math::
E(u,v) \approx \sum _{x,y} u^{2}I_{x}^{2} + 2uvI_{x}I_{y} + v^{2}I_{y}^{2}
* Which can be expressed in a matrix form as:
.. math::
E(u,v) \approx \begin{bmatrix}
u & v
u & v
\end{bmatrix}
\left (
\displaystyle \sum_{x,y}
w(x,y)
\begin{bmatrix}
I_x^{2} & I_{x}I_{y} \\
I_xI_{y} & I_{y}^{2}
I_xI_{y} & I_{y}^{2}
\end{bmatrix}
\right )
\right )
\begin{bmatrix}
u \\
v
\end{bmatrix}
v
\end{bmatrix}
* Let's denote:
.. math::
M = \displaystyle \sum_{x,y}
w(x,y)
w(x,y)
\begin{bmatrix}
I_x^{2} & I_{x}I_{y} \\
I_xI_{y} & I_{y}^{2}
I_xI_{y} & I_{y}^{2}
\end{bmatrix}
* So, our equation now is:
@@ -126,34 +126,34 @@ How does it work?
.. math::
E(u,v) \approx \begin{bmatrix}
u & v
u & v
\end{bmatrix}
M
\begin{bmatrix}
u \\
v
\end{bmatrix}
v
\end{bmatrix}
* A score is calculated for each window, to determine if it can possibly contain a corner:
.. math::
R = det(M) - k(trace(M))^{2}
R = det(M) - k(trace(M))^{2}
where:
* det(M) = :math:`\lambda_{1}\lambda_{2}`
* trace(M) = :math:`\lambda_{1}+\lambda_{2}`
a window with a score :math:`R` greater than a certain value is considered a "corner"
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp>`_
.. code-block:: cpp
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
@@ -161,7 +161,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace cv;
using namespace std;
/// Global variables
@@ -186,7 +186,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
createTrackbar( "Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo );
imshow( source_window, src );
cornerHarris_demo( 0, 0 );
waitKey(0);
@@ -204,25 +204,25 @@ This tutorial code's is shown lines below. You can also download it from `here <
int blockSize = 2;
int apertureSize = 3;
double k = 0.04;
/// Detecting corners
cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
/// Normalizing
normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
convertScaleAbs( dst_norm, dst_norm_scaled );
convertScaleAbs( dst_norm, dst_norm_scaled );
/// Drawing a circle around corners
for( int j = 0; j < dst_norm.rows ; j++ )
{ for( int i = 0; i < dst_norm.cols; i++ )
{
if( (int) dst_norm.at<float>(j,i) > thresh )
{
circle( dst_norm_scaled, Point( i, j ), 5, Scalar(0), 2, 8, 0 );
{
circle( dst_norm_scaled, Point( i, j ), 5, Scalar(0), 2, 8, 0 );
}
}
}
/// Showing the result
}
}
/// Showing the result
namedWindow( corners_window, CV_WINDOW_AUTOSIZE );
imshow( corners_window, dst_norm_scaled );
}
@@ -237,11 +237,11 @@ Result
The original image:
.. image:: images/Harris_Detector_Original_Image.jpg
:align: center
:align: center
The detected corners are surrounded by a small black circle
.. image:: images/Harris_Detector_Result.jpg
:align: center
:align: center