#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;
}
OpenCV特征点提取与匹配
最新推荐文章于 2025-02-13 21:54:23 发布
本文介绍了一种基于ORB( Oriented FAST and Rotated BRIEF)特征检测和描述符的图像特征点匹配方法,该方法应用于实时视频流中,通过摄像头捕获连续帧并进行特征点检测、描述符计算、特征点匹配及可视化展示。
1691

被折叠的 条评论
为什么被折叠?



