Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
73862699
Commit
73862699
authored
Jul 12, 2011
by
Ana Huaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added cornerDetector_Demo.cpp sample for tutorial of cornerMinEigenVal and cornerEigenValsAndVecs
parent
21409de1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
0 deletions
+123
-0
cornerDetector_Demo.cpp
.../cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp
+123
-0
No files found.
samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp
0 → 100644
View file @
73862699
/**
* @function cornerDetector_Demo.cpp
* @brief Demo code for detecting corners using OpenCV built-in functions
* @author OpenCV team
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using
namespace
cv
;
using
namespace
std
;
/// Global variables
Mat
src
,
src_gray
;
Mat
myHarris_dst
;
Mat
myHarris_copy
;
Mat
Mc
;
Mat
myShiTomasi_dst
;
Mat
myShiTomasi_copy
;
int
myShiTomasi_qualityLevel
=
50
;
int
myHarris_qualityLevel
=
50
;
int
max_qualityLevel
=
100
;
double
myHarris_minVal
;
double
myHarris_maxVal
;
double
myShiTomasi_minVal
;
double
myShiTomasi_maxVal
;
RNG
rng
(
12345
);
char
*
myHarris_window
=
"My Harris corner detector"
;
char
*
myShiTomasi_window
=
"My Shi Tomasi corner detector"
;
/// Function headers
void
myShiTomasi_function
(
int
,
void
*
);
void
myHarris_function
(
int
,
void
*
);
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
cvtColor
(
src
,
src_gray
,
CV_BGR2GRAY
);
/// Set some parameters
int
blockSize
=
3
;
int
apertureSize
=
3
;
/// My Harris matrix -- Using cornerEigenValsAndVecs
myHarris_dst
=
Mat
::
zeros
(
src_gray
.
size
(),
CV_32FC
(
6
)
);
Mc
=
Mat
::
zeros
(
src_gray
.
size
(),
CV_32FC1
);
cornerEigenValsAndVecs
(
src_gray
,
myHarris_dst
,
blockSize
,
apertureSize
,
BORDER_DEFAULT
);
/* calculate Mc */
for
(
int
j
=
0
;
j
<
src_gray
.
rows
;
j
++
)
{
for
(
int
i
=
0
;
i
<
src_gray
.
cols
;
i
++
)
{
float
lambda_1
=
myHarris_dst
.
at
<
float
>
(
j
,
i
,
0
);
float
lambda_2
=
myHarris_dst
.
at
<
float
>
(
j
,
i
,
1
);
Mc
.
at
<
float
>
(
j
,
i
)
=
lambda_1
*
lambda_2
-
0.04
*
pow
(
(
lambda_1
+
lambda_2
),
2
);
}
}
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
);
myHarris_function
(
0
,
0
);
/// My Shi-Tomasi -- Using cornerMinEigenVal
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
);
myShiTomasi_function
(
0
,
0
);
waitKey
(
0
);
return
(
0
);
}
/**
* @function myShiTomasi_function
*/
void
myShiTomasi_function
(
int
,
void
*
)
{
myShiTomasi_copy
=
src
.
clone
();
if
(
myShiTomasi_qualityLevel
<
1
)
{
myShiTomasi_qualityLevel
=
1
;
}
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
-
myShiTomasi_minVal
)
*
myShiTomasi_qualityLevel
/
max_qualityLevel
)
{
circle
(
myShiTomasi_copy
,
Point
(
i
,
j
),
4
,
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
),
-
1
,
8
,
0
);
}
}
}
imshow
(
myShiTomasi_window
,
myShiTomasi_copy
);
}
/**
* @function myHarris_function
*/
void
myHarris_function
(
int
,
void
*
)
{
myHarris_copy
=
src
.
clone
();
if
(
myHarris_qualityLevel
<
1
)
{
myHarris_qualityLevel
=
1
;
}
for
(
int
j
=
0
;
j
<
src_gray
.
rows
;
j
++
)
{
for
(
int
i
=
0
;
i
<
src_gray
.
cols
;
i
++
)
{
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
),
rng
.
uniform
(
0
,
255
)
),
-
1
,
8
,
0
);
}
}
}
imshow
(
myHarris_window
,
myHarris_copy
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment