iOS利用opencv库拼接图片的另一种方法

iOS利⽤opencv库拼接图⽚的另⼀种⽅法
问题说明
在Xcode9中,如果直接将图⽚等⽂件拖拽进项⽬中,可能会识别不到。这时候,我们通过Add Files to xxx的⽅式来进⾏添加。
项⽬⽬录⽂件结构
image
主要代码
⼀、合成代码
#include "opencv2.framework/Headers/opencv.hpp"
#include "opencv2.framework/Headers/legacy/legacy.hpp"
#include "opencv2.framework/Headers/nonfree/nonfree.hpp"
#include <vector>
#include <iostream>
#include <iostream>
using namespace std;
using namespace cv;
/
/计算原始图像点位在经过矩阵变换后在⽬标图像上对应位置
Point2f getTransformPoint(const Point2f originalPoint,const Mat &transformMaxtri){
Mat originelP,targetP;
originelP=(Mat_<double>(3,1)<<originalPoint.x,originalPoint.y,1.0);
targetP=transformMaxtri*originelP;
float x=targetP.at<double>(0,0)/targetP.at<double>(2,0);
float y=targetP.at<double>(1,0)/targetP.at<double>(2,0);
return Point2f(x,y);
}
- (UIImage *)composeImage{
NSString *path01 = [[NSBundle mainBundle] pathForResource:@"test01" ofType:@"jpg"];    NSStrin
g *path02 = [[NSBundle mainBundle] pathForResource:@"test02" ofType:@"jpg"];    Mat img01;
Mat img02;
if (path01 == nil && path02 == nil) {
return [UIImage new];
}
else{
img01 = imread([path01 UTF8String]);
img02 = imread([path02 UTF8String]);
//如果没有读取到image
和嫩太阳能庭院灯if (!img01.data && !img02.data) {
return [UIImage new];
}
//灰度图转换
Mat img_h_01 ,img_h_02;
cvtColor(img01, img_h_01, CV_RGB2GRAY);
cvtColor(img02, img_h_02, CV_RGB2GRAY);
//提取特征
蜂鸣器电路
SiftFeatureDetector siftDetector(800);
vector<KeyPoint> keyPoint1,KeyPoint2;
siftDetector.detect(img_h_01, keyPoint1);
siftDetector.detect(img_h_02, KeyPoint2);
//特征点描述,为下⾯的特征点匹配做准备
SiftDescriptorExtractor siftDescriptor;
Mat img_description_01,img_description_02;
siftDescriptorpute(img_h_01, keyPoint1, img_description_01);
siftDescriptorpute(img_h_02, KeyPoint2, img_description_02);
//获得匹配特征点,并提取最优配对
FlannBasedMatcher matcher;
vector<DMatch> matchePoints;
matcher.match(img_description_01,img_description_02,matchePoints,Mat());
sort(matchePoints.begin(), d());//特征点排序
//获取排在前N个的最优配对美光隐形眼镜
vector<Point2f> imagePoints1,imagePoints2;
for (int i = 0; i < 10; i++) {
imagePoints1.push_back(keyPoint1[matchePoints[i].queryIdx].pt);
imagePoints2.push_back(KeyPoint2[matchePoints[i].trainIdx].pt);
}
//获取img1到img2的投影映射矩阵,尺⼨为3*3
Mat homo = findHomography(imagePoints1, imagePoints2, CV_RANSAC);
Mat adjustMat = (Mat_<double>(3,3)<<1.0,ls,0,1.0,0,0,0,1.0);
Mat adjustHomo = adjustMat * homo;车载制氧机
//获得最强配对点在原始图像和矩阵变换后图像上的对应位置,⽤于图像拼接点的定位
Point2f originalLinkPoint,targetLintPoint,basedImagePoint;挺腰器
originalLinkPoint = keyPoint1[matchePoints[0].queryIdx].pt;
滤油机滤布
targetLintPoint = getTransformPoint(originalLinkPoint, adjustHomo);
basedImagePoint = KeyPoint2[matchePoints[0].trainIdx].pt;

本文发布于:2024-09-23 23:30:39,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/227358.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:图像   特征   矩阵   可能
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议