多个相机固定空间位置的简单拼接orb_flann

参考网址:https://www.cnblogs.com/skyfsm/p/7411961.html

Mat img_1 = imread(“left3.jpg”,0);
Mat img_2 = imread( “right3.jpg”,0 );

if( !img_1.data || !img_2.data )
{
cout<< ” –(!) Error reading images ” << endl;
return -1;
}

//– Step 1: Detect the keypoints using ORB Detector

cv::Ptr orb = cv::ORB::create(200);

std::vector keypoints_1, keypoints_2;

orb->detect( img_1, keypoints_1 );
orb->detect( img_2, keypoints_2 );
//– Step 2: Calculate descriptors (feature vectors)

Mat descriptors_1, descriptors_2;

// descriptor is a cv::Mat, with rows the same as nFeatures, and cols as 32 (8UC1)
orb->compute( img_1, keypoints_1, descriptors_1 );
orb->compute( img_2, keypoints_2, descriptors_2 );
cout << type2str(descriptors_1.type()) << ” ” << descriptors_1.rows << “*” << descriptors_1.cols << endl;;

clock_t start,finish;
double totaltime;
start=clock();
//– Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector matches;

// the descriptor for FlannBasedMatcher should has matrix element of CV_32F
if( descriptors_1.type()!=CV_32F )
{
descriptors_1.convertTo( descriptors_1, CV_32F );
descriptors_2.convertTo( descriptors_2, CV_32F );
}
matcher.match( descriptors_1, descriptors_2, matches );

double min_dist = min_element( matches.begin(),
matches.end(),
[]( const DMatch& d1, const DMatch& d2 )->double
{
return d1.distance < d2.distance;
} )->distance;

cout << min_dist << endl;

vector good_matches;

for( int i = 0; i < descriptors_1.rows; i++ )
{
if( matches[i].distance < max( min_dist*2, 60.0 ) )
{
good_matches.push_back( matches[i]);
}
}

int x = 0;
int y = 0;
for(int i = 0; i < good_matches.size(); i++)
{

  x +=  keypoints_1[good_matches[i].queryIdx].pt.x - keypoints_2[good_matches[i].trainIdx].pt.x;
  y +=  keypoints_1[good_matches[i].queryIdx].pt.y - keypoints_2[good_matches[i].trainIdx].pt.y;

}
cout << “x = ” << x/good_matches.size() << endl;
cout << “Y = ” << y/good_matches.size() << endl;

Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

//– Show detected matches
imshow( “Good Matches”, img_matches );

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

城墙郭外斜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值