Skip to content

Instantly share code, notes, and snippets.

@hoozh
Created September 7, 2017 08:31
Show Gist options
  • Save hoozh/e67ebb996ee2dbbb55f3bbb8538ecf70 to your computer and use it in GitHub Desktop.
Save hoozh/e67ebb996ee2dbbb55f3bbb8538ecf70 to your computer and use it in GitHub Desktop.
OpenCV cvGoodFeaturesToTrack
#include <opencv2/opencv.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
// Load a color image, and convert it into grayscale
char filename[260];
for (int i = 1; i < 14; i++) {
sprintf(filename, "./1/%d.png", i);
IplImage* img = cvLoadImage(filename, CV_LOAD_IMAGE_COLOR);
assert(NULL != img);
IplImage* img_gray = cvCreateImage(cvGetSize(img), 8, 1);
cvCvtColor(img, img_gray, CV_BGR2GRAY);
// Create temporary images required by cvGoodFeaturesToTrack
IplImage* img_temp = cvCreateImage(cvGetSize(img), 32, 1);
IplImage* img_eigen = cvCreateImage(cvGetSize(img), 32, 1);
// Create the array to store the points detected( <= 1000 )
int count = 1000;
CvPoint2D32f* corners = new CvPoint2D32f[count];
// Find corners
cvGoodFeaturesToTrack(img_gray, img_eigen, img_temp, corners, &count, 0.1, 10);
// Mark these corners on the original image
for (int i = 0; i<count; i++)
cvLine(img, cvPoint(corners[i].x, corners[i].y), cvPoint(corners[i].x, corners[i].y), CV_RGB(255, 0, 0), 5);
// Display it
cvNamedWindow(filename);
cvShowImage(filename, img);
// Print the number of corners
printf("Detected Points : %d\n", count);
}
cvWaitKey(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment