Download samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp from tgollogly/test: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/tgollogly/test/resolve/main/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
- Command line
-
hf download hf://tgollogly/test/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
-
curl -L -o goodFeaturesToTrack_Demo.cpp https://huggingface.co/tgollogly/test/resolve/main/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
2.59 kB
| /** | |
| * @function goodFeaturesToTrack_Demo.cpp | |
| * @brief Demo code for detecting corners using Shi-Tomasi method | |
| * @author OpenCV team | |
| */ | |
| 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 argc, char** argv ) | |
| { | |
| /// Load source image and convert it to gray | |
| CommandLineParser parser( argc, argv, "{@input | pic3.png | input image}" ); | |
| src = imread( samples::findFile( parser.get<String>( "@input" ) ) ); | |
| if( src.empty() ) | |
| { | |
| cout << "Could not open or find the image!\n" << endl; | |
| cout << "Usage: " << argv[0] << " <Input image>" << endl; | |
| return -1; | |
| } | |
| cvtColor( src, src_gray, COLOR_BGR2GRAY ); | |
| /// Create Window | |
| namedWindow( source_window ); | |
| /// 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(); | |
| return 0; | |
| } | |
| /** | |
| * @function goodFeaturesToTrack_Demo.cpp | |
| * @brief Apply Shi-Tomasi corner detector | |
| */ | |
| void goodFeaturesToTrack_Demo( int, void* ) | |
| { | |
| /// Parameters for Shi-Tomasi algorithm | |
| maxCorners = MAX(maxCorners, 1); | |
| vector<Point2f> corners; | |
| double qualityLevel = 0.01; | |
| double minDistance = 10; | |
| int blockSize = 3, gradientSize = 3; | |
| bool useHarrisDetector = false; | |
| double k = 0.04; | |
| /// Copy the source image | |
| Mat copy = src.clone(); | |
| /// Apply corner detection | |
| goodFeaturesToTrack( src_gray, | |
| corners, | |
| maxCorners, | |
| qualityLevel, | |
| minDistance, | |
| Mat(), | |
| blockSize, | |
| gradientSize, | |
| useHarrisDetector, | |
| k ); | |
| /// Draw corners detected | |
| cout << "** Number of corners detected: " << corners.size() << endl; | |
| int radius = 4; | |
| for( size_t i = 0; i < corners.size(); i++ ) | |
| { | |
| circle( copy, corners[i], radius, Scalar(rng.uniform(0,255), rng.uniform(0, 256), rng.uniform(0, 256)), FILLED ); | |
| } | |
| /// Show what you got | |
| namedWindow( source_window ); | |
| imshow( source_window, copy ); | |
| } | |