Ask Your Question

Revision history [back]

As suggested by @berak, after fixing indexing and conversion, the following result works flawlessly

// Now lets detect the strong minutiae using Haris corner detection
Mat harris_corners, harris_normalised;
harris_corners = Mat::zeros(input_thinned.size(), CV_32FC1);
cornerHarris(input_thinned, harris_corners, 2, 3, 0.04, BORDER_DEFAULT);
normalize(harris_corners, harris_normalised, 0, 255, NORM_MINMAX, CV_32FC1, Mat());

// Select the strongest corners that you want
int threshold = 125;
vector<KeyPoint> keypoints;

// Make a color clone for visualisation purposes
Mat rescaled;
convertScaleAbs(harris_normalised, rescaled);
Mat harris_c(rescaled.rows, rescaled.cols, CV_8UC3);
Mat in[] = { rescaled, rescaled, rescaled };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( in, 3, &harris_c, 1, from_to, 3 );

for(int x=0; x<harris_normalised.cols; x++){
   for(int y=0; y<harris_normalised.rows; y++){
      if ( (int)harris_normalised.at<float>(y, x) > threshold ){
         // Draw or store the keypoint location here, just like you decide. In our case we will store the location of the keypoint
         circle(harris_c, Point(x, y), 5, Scalar(0,255,0), 1);
         circle(harris_c, Point(x, y), 1, Scalar(0,0,255), 1);
         keypoints.push_back( KeyPoint (x, y, 1) );
      }
   }
}
imshow("temp", harris_c); waitKey(0);