1. 程式人生 > >萌新學習手冊:surf特徵檢測

萌新學習手冊:surf特徵檢測

#include<opencv2/xfeatures2d.hpp>
using namespace xfeatures2d;

 嗯,在開頭要包含這個庫然後申明名稱空間

src = imread("C:/Users/pbiha/Desktop/image/1.png",IMREAD_GRAYSCALE);

IMREAD_GRAYSCALE就是0,表示讀入一張灰度影象

Ptr<>

這是一個智慧指標像指標一樣的用,但是更加方便記憶體的管理

#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/xfeatures2d.hpp>
using namespace xfeatures2d;
using namespace std;
using namespace cv;


int main() {
	Mat src,result_img;
	src = imread("C:/Users/pbiha/Desktop/image/1.png",IMREAD_GRAYSCALE);
	if (src.empty()) {
		puts("Can't find the img...");
		return -1;
	}
	namedWindow("input", CV_WINDOW_AUTOSIZE);
	imshow("input", src);
	int minHessian = 300;
	Ptr<SURF>detector = SURF::create(minHessian);
	vector<KeyPoint>ketpoints;
	detector->detect(src, ketpoints, Mat());
	drawKeypoints(src, ketpoints, result_img, Scalar::all(-1),DrawMatchesFlags::DEFAULT);
	namedWindow("outputimg", CV_WARP_FILL_OUTLIERS);
	imshow("outputimg", result_img);
	waitKey(0);
	return 0;
}