18 Mat myHarris_dst;
Mat myHarris_copy;
Mat Mc;
19 Mat myShiTomasi_dst;
Mat myShiTomasi_copy;
21 int myShiTomasi_qualityLevel = 50;
22 int myHarris_qualityLevel = 50;
23 int max_qualityLevel = 100;
25 double myHarris_minVal;
double myHarris_maxVal;
26 double myShiTomasi_minVal;
double myShiTomasi_maxVal;
30 const char* myHarris_window =
"My Harris corner detector";
31 const char* myShiTomasi_window =
"My Shi Tomasi corner detector";
34 void myShiTomasi_function(
int,
void* );
35 void myHarris_function(
int,
void* );
40 int main(
int,
char** argv )
43 src =
imread( argv[1], 1 );
47 int blockSize = 3;
int apertureSize = 3;
56 for(
int j = 0; j < src_gray.rows; j++ )
57 {
for(
int i = 0; i < src_gray.cols; i++ )
59 float lambda_1 = myHarris_dst.at<
Vec6f>(j,
i)[0];
60 float lambda_2 = myHarris_dst.at<
Vec6f>(j,
i)[1];
61 Mc.at<
float>(j,
i) = lambda_1*lambda_2 - 0.04f*
pow( ( lambda_1 + lambda_2 ), 2 );
65 minMaxLoc( Mc, &myHarris_minVal, &myHarris_maxVal, 0, 0,
Mat() );
69 createTrackbar(
" Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel, myHarris_function );
70 myHarris_function( 0, 0 );
76 minMaxLoc( myShiTomasi_dst, &myShiTomasi_minVal, &myShiTomasi_maxVal, 0, 0,
Mat() );
80 createTrackbar(
" Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel, myShiTomasi_function );
81 myShiTomasi_function( 0, 0 );
90 void myShiTomasi_function(
int,
void* )
92 myShiTomasi_copy = src.clone();
94 if( myShiTomasi_qualityLevel < 1 ) { myShiTomasi_qualityLevel = 1; }
96 for(
int j = 0; j < src_gray.rows; j++ )
97 {
for(
int i = 0; i < src_gray.cols; i++ )
99 if( myShiTomasi_dst.at<
float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal - myShiTomasi_minVal )*myShiTomasi_qualityLevel/max_qualityLevel )
100 {
circle( myShiTomasi_copy,
Point(i,j), 4,
Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
103 imshow( myShiTomasi_window, myShiTomasi_copy );
109 void myHarris_function(
int,
void* )
111 myHarris_copy = src.clone();
113 if( myHarris_qualityLevel < 1 ) { myHarris_qualityLevel = 1; }
115 for(
int j = 0; j < src_gray.rows; j++ )
116 {
for(
int i = 0; i < src_gray.cols; i++ )
118 if( Mc.at<
float>(j,i) > myHarris_minVal + ( myHarris_maxVal - myHarris_minVal )*myHarris_qualityLevel/max_qualityLevel )
119 {
circle( myHarris_copy,
Point(i,j), 4,
Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
122 imshow( myHarris_window, myHarris_copy );
Scalar_< double > Scalar
Definition: types.hpp:597
void minMaxLoc(InputArray src, double *minVal, double *maxVal=0, Point *minLoc=0, Point *maxLoc=0, InputArray mask=noArray())
Finds the global minimum and maximum in an array.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
static MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
#define CV_32FC(n)
Definition: cvdef.h:150
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:300
void cornerEigenValsAndVecs(InputArray src, OutputArray dst, int blockSize, int ksize, int borderType=BORDER_DEFAULT)
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
for i
Definition: modelConvert.m:63
#define CV_32FC1
Definition: cvdef.h:146
Random Number Generator.
Definition: core.hpp:2600
void pow(InputArray src, double power, OutputArray dst)
Raises every array element to a power.
Definition: highgui.hpp:138
void cornerMinEigenVal(InputArray src, OutputArray dst, int blockSize, int ksize=3, int borderType=BORDER_DEFAULT)
Calculates the minimal eigenvalue of gradient matrices for corner detection.
same as BORDER_REFLECT_101
Definition: base.hpp:242
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
n-dimensional dense array class
Definition: mat.hpp:726
void circle(InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a circle.
Point2i Point
Definition: types.hpp:181
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc.hpp:511
int waitKey(int delay=0)
Waits for a pressed key.