#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<stdlib.h>
using namespace std;
using namespace cv;
Mat image ,image_gray;
int max_corners = 20;
void on_slider(int,void*)
{
if(image_gray.empty()) return;
max_corners = max(1, max_corners);
setTrackbarPos("Max No. of corners","Corners",max_corners);
}
int main()
{
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"Can't get Video..."<<endl;
exit(-1);
}
namedWindow("Corners");
createTrackbar("Max No. of corners","Corners",&max_corners,250,on_slider);
while((char)waitKey(1) != 'q' && cap.isOpened())
{
cap >> image;
cvtColor(image,image_gray,CV_RGB2GRAY);
float quality = 0.01;
int min_distance = 10;
vector<Point2d> corners;
goodFeaturesToTrack(image_gray , corners,max_corners,quality,min_distance);
Mat image_corners = image.clone();
for(int i = 0 ; i < corners.size() ; i++)
{
circle(image_corners,corners[i],3,CV_RGB(255,0,0),-1);
}
imshow("Corners",image_corners);
}
return 0;
}
測試偵測和式門結果
留言列表