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
6c9f4d64
Commit
6c9f4d64
authored
Jul 11, 2011
by
Ana Huaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added goodFeaturesToTrack_Demo.cpp code for tutorials
parent
e2da35dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
goodFeaturesToTrack_Demo.cpp
...tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
+93
-0
No files found.
samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
0 → 100644
View file @
6c9f4d64
/**
* @function goodFeaturesToTrack_Demo.cpp
* @brief Demo code for detecting corners using Shi-Tomasi method
* @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
;
int
maxCorners
=
23
;
int
maxTrackbar
=
100
;
RNG
rng
(
12345
);
char
*
source_window
=
"Image"
;
/// Function header
void
goodFeaturesToTrack_Demo
(
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
);
/// Create Window
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
/// Create Trackbar to set the number of corners
createTrackbar
(
"Max corners:"
,
source_window
,
&
maxCorners
,
maxTrackbar
,
goodFeaturesToTrack_Demo
);
imshow
(
source_window
,
src
);
goodFeaturesToTrack_Demo
(
0
,
0
);
waitKey
(
0
);
return
(
0
);
}
/**
* @function goodFeaturesToTrack_Demo.cpp
* @brief Apply Shi-Tomasi corner detector
*/
void
goodFeaturesToTrack_Demo
(
int
,
void
*
)
{
if
(
maxCorners
<
1
)
{
maxCorners
=
1
;
}
/// Parameters for Shi-Tomasi algorithm
vector
<
Point2f
>
corners
;
double
qualityLevel
=
0.01
;
double
minDistance
=
10
;
int
blockSize
=
3
;
bool
useHarrisDetector
=
false
;
double
k
=
0.04
;
/// Copy the source image
Mat
copy
;
copy
=
src
.
clone
();
/// Apply corner detection
goodFeaturesToTrack
(
src_gray
,
corners
,
maxCorners
,
qualityLevel
,
minDistance
,
Mat
(),
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
),
rng
.
uniform
(
0
,
255
)),
-
1
,
8
,
0
);
}
/// Show what you got
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
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