Opencv-Harris corner detection

Source: Internet
Author: User

For the implementation routine of this article, see the English tutorial feature2d module.2d features framework-> Harris corner detector

The specific algorithm uses the Taylor expansion to obtain the maximum change point of the pixel value in the window, that is, the corner point position.

/** * @function cornerHarris_Demo.cpp * @brief Demo code for detecting corners using Harris-Stephens 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 variablesMat src, src_gray;int thresh = 200;int max_thresh = 255;const char* source_window = "Source image";const char* corners_window = "Corners detected";/// Function headervoid cornerHarris_demo( int, void* );/** * @function main */int main( int, char** argv ){  /// Load source image and convert it to gray  src = imread( argv[1], 1 );  cvtColor( src, src_gray, COLOR_BGR2GRAY );  /// Create a window and a trackbar  namedWindow( source_window, WINDOW_AUTOSIZE );  createTrackbar( "Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo );  imshow( source_window, src );  cornerHarris_demo( 0, 0 );  waitKey(0);  return(0);}/** * @function cornerHarris_demo * @brief Executes the corner detection and draw a circle around the possible corners */void cornerHarris_demo( int, void* ){  Mat dst, dst_norm, dst_norm_scaled;  dst = Mat::zeros( src.size(), CV_32FC1 );  /// Detector parameters  int blockSize = 2;  int apertureSize = 3;  double k = 0.04;  /// Detecting corners  cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT );  /// Normalizing  normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );  convertScaleAbs( dst_norm, dst_norm_scaled );  /// Drawing a circle around corners  for( int j = 0; j < dst_norm.rows ; j++ )     { for( int i = 0; i < dst_norm.cols; i++ )          {            if( (int) dst_norm.at<float>(j,i) > thresh )              {               circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );              }          }     }  /// Showing the result  namedWindow( corners_window, WINDOW_AUTOSIZE );  imshow( corners_window, dst_norm_scaled );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.