mirror of
https://github.com/opencv/opencv.git
synced 2024-12-21 22:12:02 +08:00
39e742765a
Added gradiantSize param into goodFeaturesToTrack API (#9618) * Added gradiantSize param into goodFeaturesToTrack API Removed hardcode value 3 in goodFeaturesToTrack API, and added new param 'gradinatSize' in this API so that user can pass any gradiant size as 3, 5 or 7. Signed-off-by: Vipin Anand <anand.vipin@gmail.com> Signed-off-by: Nilaykumar Patel<nilay.nilpat@gmail.com> Signed-off-by: Prashanth Voora <prashanthx85@gmail.com> * fixed compilation error for java test Signed-off-by: Vipin Anand <anand.vipin@gmail.com> * Modifying code for previous binary compatibility and fixing other warnings fixed ABI break issue resolved merged conflict compilation error fix Signed-off-by: Vipin Anand <anand.vipin@gmail.com> Signed-off-by: Patel, Nilaykumar K <nilay.nilpat@gmail.com>
93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
/**
|
|
* @function goodFeaturesToTrack_Demo.cpp
|
|
* @brief Demo code for detecting corners using Shi-Tomasi method
|
|
* @author OpenCV team
|
|
*/
|
|
|
|
#include "opencv2/imgcodecs.hpp"
|
|
#include "opencv2/highgui.hpp"
|
|
#include "opencv2/imgproc.hpp"
|
|
#include <iostream>
|
|
|
|
using namespace cv;
|
|
using namespace std;
|
|
|
|
/// Global variables
|
|
Mat src, src_gray;
|
|
|
|
int maxCorners = 23;
|
|
int maxTrackbar = 100;
|
|
|
|
RNG rng(12345);
|
|
const char* source_window = "Image";
|
|
|
|
/// Function header
|
|
void goodFeaturesToTrack_Demo( int, void* );
|
|
|
|
/**
|
|
* @function main
|
|
*/
|
|
int main( int, char** argv )
|
|
{
|
|
/// Load source image and convert it to gray
|
|
src = imread( argv[1], IMREAD_COLOR );
|
|
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
|
|
|
/// Create Window
|
|
namedWindow( source_window, 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, gradiantSize = 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,
|
|
gradiantSize,
|
|
useHarrisDetector,
|
|
k );
|
|
|
|
|
|
/// Draw corners detected
|
|
cout<<"** Number of corners detected: "<<corners.size()<<endl;
|
|
int r = 4;
|
|
for( size_t 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, WINDOW_AUTOSIZE );
|
|
imshow( source_window, copy );
|
|
}
|