双目和多目摄像头对齐与拼接
Posted 残诗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了双目和多目摄像头对齐与拼接相关的知识,希望对你有一定的参考价值。
双目摄像头或者多目组合摄像头因为组装工艺原因可能会有瑕疵,表现在拍照录相上是图像焦点不在一个水平线或者垂直线,一般场合勉强可用,对精度有要求的场合,需要校正。比如使双目图像录相处于同一水平线,多目拼接也需要找到共同点合并。这可以使用opencv实现,寻找不同图像的相似点,进一步调优,通过比较相以点的坐标,计算出偏移,在拍照和录相时进行校正。
public static Mat FeatureOrbLannbased(Mat src, Mat dst)
FeatureDetector fd = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor de = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher Matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_L1);
MatOfKeyPoint mkp = new MatOfKeyPoint();
fd.detect(src, mkp);
Mat desc = new Mat();
de.compute(src, mkp, desc);
Features2d.drawKeypoints(src, mkp, src);
MatOfKeyPoint mkp2 = new MatOfKeyPoint();
fd.detect(dst, mkp2);
Mat desc2 = new Mat();
de.compute(dst, mkp2, desc2);
Features2d.drawKeypoints(dst, mkp2, dst);
// Matching features
MatOfDMatch Matches = new MatOfDMatch();
Matcher.match(desc, desc2, Matches);
// 筛选点
double maxDist = Double.MIN_VALUE;
double minDist = Double.MAX_VALUE;
DMatch[] mats = Matches.toArray();
for (int i = 0; i < mats.length; i++)
double dist = mats[i].distance;
if (dist < minDist)
minDist = dist;
if (dist > maxDist)
maxDist = dist;
System.out.println("Min Distance:" + minDist);
System.out.println("Max Distance:" + maxDist);
List<DMatch> goodMatch = new LinkedList<>();
KeyPoint[] smkp = mkp.toArray();
KeyPoint[] dmkp = mkp2.toArray();
// double[] arr = new double[mats.length];
List<Double> list = new ArrayList<>();
for (int i = 0; i < mats.length; i++)
// 相似度,越小越相似
System.out.println("mats[i].distance:" + mats[i].distance);
// 原始点坐标
System.out.println("smkp x:" + smkp[mats[i].queryIdx].pt.x);
System.out.println("smkp y:" + smkp[mats[i].queryIdx].pt.y);
// 目标点坐标
System.out.println("dmkp x:" + dmkp[mats[i].trainIdx].pt.x);
System.out.println("dmkp y:" + dmkp[mats[i].trainIdx].pt.y);
//对相似性最高的坐标过滤
if ((mats[i].distance >= minDist) && (mats[i].distance < minDist + 100f))
goodMatch.add(mats[i]);
list.add(dmkp[mats[i].trainIdx].pt.y - smkp[mats[i].queryIdx].pt.y);
Matches.fromList(goodMatch);
// Show result
Mat OutImage = new Mat();
Features2d.drawMatches(src, mkp, dst, mkp2, Matches, OutImage);
double[] arr = convert2doubleArray(list.toArray(new Double[list.size()]));
//获取Y轴偏差
countMatches(arr);
return OutImage;
以上是关于双目和多目摄像头对齐与拼接的主要内容,如果未能解决你的问题,请参考以下文章