Created
October 25, 2015 00:00
-
-
Save clynamen/9a265111a87807cd0b74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "opencv2/highgui/highgui.hpp" | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include "opencv2/core/core.hpp" | |
using namespace std; | |
using namespace cv; | |
int main(int argc, char **argv) { | |
Mat image; | |
image = imread("chessboard.png", CV_LOAD_IMAGE_COLOR); // Read the file | |
if(!image.data) { | |
cerr << "Unable to find image" << endl; | |
return -1; | |
} | |
namedWindow("original", CV_WINDOW_AUTOSIZE); | |
imshow("original", image); | |
Mat grayImage; | |
cvtColor(image, grayImage, CV_BGR2GRAY); | |
Mat harrisImage; | |
cornerHarris(grayImage, harrisImage, 2, 3, 0.04); | |
namedWindow("harris", CV_WINDOW_AUTOSIZE); | |
vector<Mat> channels; | |
Mat normalized; | |
normalize(harrisImage, normalized, 0, 255, NORM_MINMAX, CV_32FC1, Mat() ); | |
/// Drawing a circle around corners | |
for( int j = 0; j < normalized.rows ; j++ ) { | |
for( int i = 0; i < normalized.cols; i++ ) { | |
if( (int) normalized.at<float>(j,i) > 200 ) { | |
circle(image, Point( i, j ), 8, Scalar(0, 0, 0xff), 1, 1, 0 ); | |
} | |
} | |
} | |
imshow("harris", image); | |
while(true) { | |
if (waitKey(30) == 27) | |
{ | |
cout << "esc key is pressed by user" << endl; | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment