OpenCV特征点提取与匹配

#include<opencv2/opencv.hpp>   
#include<vector>

using namespace std;
using namespace cv;

int feature_show(Mat srcImage, Mat old_frame)
{

    vector<KeyPoint>detectKeyPoint;
	vector<KeyPoint>old_detectKeyPoint;

    Mat keyPointImage, desriptors;
	Mat old_keyPointImage, old_desriptors;

    Ptr<Feature2D> orb = ORB::create();

	//提取特征点
    orb->detect(srcImage, detectKeyPoint);
	orb->detect(old_frame, old_detectKeyPoint);

	//计算描述子
	orb->compute(srcImage, detectKeyPoint, desriptors);
	orb->compute(old_frame, old_detectKeyPoint, old_desriptors);

	//绘制特征点
    drawKeypoints(srcImage, detectKeyPoint, keyPointImage, Scalar(0, 0, 255), DrawMatchesFlags::DEFAULT);
	drawKeypoints(old_frame, old_detectKeyPoint, old_keyPointImage, Scalar(0, 0, 255), DrawMatchesFlags::DEFAULT);

	//匹配特征点
	vector<DMatch> matches;
	BFMatcher bfmatcher(NORM_HAMMING);
	bfmatcher.match(desriptors, old_desriptors, matches);

	//绘制匹配的特征点
	Mat img_match;
	drawMatches(srcImage, detectKeyPoint, old_frame, old_detectKeyPoint, matches, img_match);

	//显示图像
    imshow("src image", srcImage);
    imshow("current", keyPointImage);
	imshow("old", old_keyPointImage);
	imshow("image match", img_match);

    waitKey(30);

    return 0;
}

int main()
{
	VideoCapture capture(1);//打开摄像头  
	if (!capture.isOpened())//没有打开摄像头的话,就返回。
		return 0;
	Mat frame, old_frame; 
	capture >> old_frame;
//循环显示每一帧  
	while (1)
	{ 
		capture >> frame;  //读取当前帧                          
		if (frame.empty())
		{
			break;
		}
		else
		{
			feature_show(frame, old_frame);
			frame.copyTo(old_frame);
		}
		//waitKey(30); //延时30ms  
	}
	capture.release();//释放资源
	destroyAllWindows();//关闭所有窗口

	return 0;
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值