I just want to try the openCV function -- cvCornerHarris. Here is my c++ code:
//image file
char imagePath[256] = "./images/lena512color.tiff";
printf("%s
", imagePath);
IplImage* srcImg = cvLoadImage(imagePath, 1);
if(NULL == srcImg){
printf("Can not open image file(s).
");
return -1;
}
IplImage* srcImgGry = cvCreateImage(cvGetSize(srcImg), IPL_DEPTH_8U, 1);
cvCvtColor(srcImg, srcImgGry, CV_RGB2GRAY);
// Canny and Harris expect grayscale (8-bit) input.
// And output of harris image must be 32-bit float .
IplImage* harrisImg = cvCreateImage(cvGetSize(srcImg), IPL_DEPTH_32F, 1);
IplImage* cannyImg = cvCreateImage(cvGetSize(srcImg), IPL_DEPTH_8U, 1);
//// Corner detection using Harris-corner
cvCornerHarris(srcImgGry, harrisImg, 5, 5, 0.04);
cvCanny(srcImgGry, cannyImg, 50, 100, 3);
// (5)Display the result
cvNamedWindow ("Img", CV_WINDOW_AUTOSIZE);
cvShowImage ("Img", srcImgGry);
cvNamedWindow ("Harris", CV_WINDOW_AUTOSIZE);
cvShowImage ("Harris", harrisImg);
cvNamedWindow ("Canny", CV_WINDOW_AUTOSIZE);
cvShowImage ("Canny", cannyImg);
cvWaitKey (0);
cvDestroyWindow ("Harris");
cvDestroyWindow ("Img");
cvReleaseImage (&srcImg);
cvReleaseImage (&srcImgGry);
cvReleaseImage (&harrisImg);
cvReleaseImage (&cannyImg);
I can get a expected output image of cvCanny
(cannyImg
) but the output image of cvCornerHarris
(harrisImg
)is an black image with nothing on it.
Please help to explain how to use this function cvCornerHarris
. Thanks!