Let us get our hands on Edge Detection Technique.
-------------------------------------------------------------
Input image:
#include<iostream>
#include<cv.h>
#include<highgui.h>
#include<stdlib.h>
using namespace std;
using namespace cv;
Mat img,img_g;
int main()
{
img=imread("images/squares.jpg");
cvtColor(img,img_g,CV_RGB2GRAY);
vector<Point2d> corners;
//creates a 2D Vector
float quality=0.01;
int min_distance=10,max_corners=50;
goodFeaturesToTrack(img_g,corners,max_corners,quality,min_distance);
//tracks good features!
//img_g: target image
//corners: stores the position of corners
//max_corners: maximum number of corners; you can vary these
// quality, min_distance, refer documentation.
Mat img_corners=img.clone();
for(int i=0;i < corners.size();i++)
circle(img_corners,corners[i],4,CV_RGB(255,0,0),-1);
// draws circles
namedWindow("Image");
imshow("Image",img_corners);
while(char(waitKey(1)) != 'q') {}
return 0;
}
--------------------------------------------------
Result:
-------------------------------------------------------------
Input image:
#include<iostream>
#include<cv.h>
#include<highgui.h>
#include<stdlib.h>
using namespace std;
using namespace cv;
Mat img,img_g;
int main()
{
img=imread("images/squares.jpg");
cvtColor(img,img_g,CV_RGB2GRAY);
vector<Point2d> corners;
//creates a 2D Vector
float quality=0.01;
int min_distance=10,max_corners=50;
goodFeaturesToTrack(img_g,corners,max_corners,quality,min_distance);
//tracks good features!
//img_g: target image
//corners: stores the position of corners
//max_corners: maximum number of corners; you can vary these
// quality, min_distance, refer documentation.
Mat img_corners=img.clone();
for(int i=0;i < corners.size();i++)
circle(img_corners,corners[i],4,CV_RGB(255,0,0),-1);
// draws circles
namedWindow("Image");
imshow("Image",img_corners);
while(char(waitKey(1)) != 'q') {}
return 0;
}
--------------------------------------------------
Result:
We are first converting the image to grayscale and then detecting the corners.
This algorithm was proposed by Shi and Tomasi.
Sources:


No comments:
Post a Comment