From 51965c99362ea1d37fddc513dba6345fb1b8ea94 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 25 May 2012 09:24:31 +0200 Subject: cvg: Add GoodFeaturesToTrack filter --- cvg.c | 35 +++++++++++++++++++++++++++++++++++ cvg.ui | 1 + 2 files changed, 36 insertions(+) diff --git a/cvg.c b/cvg.c index b6fc76e..f327ea6 100644 --- a/cvg.c +++ b/cvg.c @@ -259,6 +259,39 @@ gauss_filter(struct cvg *cvg, IplImage *image) return output; } +static IplImage * +good_features_to_track(struct cvg *cvg, IplImage *image) +{ + IplImage *output, *gray_frame, *eig_image, *temp_image; + CvPoint2D32f corners[100]; + int corner_count = sizeof(corners)/sizeof(corners[0]); + double quality_level = 0.1, min_distance = 5; + int i, eig_block_size = 3, use_harris = 0; + + output = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 3); + cvCopy(image, output, NULL); + + gray_frame = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1); + eig_image = cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, 1); + temp_image = cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, 1); + cvCvtColor(image, gray_frame, CV_BGR2GRAY); + + memset(corners, 0, sizeof corners); + cvGoodFeaturesToTrack(gray_frame, eig_image, temp_image, + corners, &corner_count, + quality_level, min_distance, NULL, + eig_block_size, use_harris, 0.04); + for (i = 0; i < corner_count; ++i) { + CvPoint center = { corners[i].x, corners[i].y }; + cvCircle(output, center, 5, CV_RGB(255, 0, 0), 3, 8, 0); + } + cvReleaseImage(&gray_frame); + cvReleaseImage(&eig_image); + cvReleaseImage(&temp_image); + + return output; +} + static IplImage * hide_filter(struct cvg *cvg, IplImage *image) { @@ -291,6 +324,8 @@ method_set(GtkComboBox *widget, gpointer userdata) return; if (strcmp(text, "Gauss") == 0) cvg->filter = gauss_filter; + else if (strcmp(text, "GoodFeaturesToTrack") == 0) + cvg->filter = good_features_to_track; else if (strcmp(text, "Pass-Through") == 0) cvg->filter = pass_through_filter; else if (strcmp(text, "Hide") == 0) diff --git a/cvg.ui b/cvg.ui index 4504994..0a821cd 100644 --- a/cvg.ui +++ b/cvg.ui @@ -83,6 +83,7 @@ Hide Gauss + GoodFeaturesToTrack Pass-Through -- cgit