使用Homography链接两个图片像素 [英] Link two pictures pixels using Homography

查看:85
本文介绍了使用Homography链接两个图片像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张相同的图片,但第二张失真并且尺寸不同.我希望能够在第一张图片上选择一个点,并在第二张图片上找到完全相同的点. 图片的同步将由每张图片上的4点组成.

I have two pictures that are the same but the second is distorted and have different dimensions. I want to be able to select a point on the first picture and find the exact same point on the second picture. The synchronisation of the pictures will be made by 4 points on each picture.

示例:
普通图片

Example:
Normal picture

图片失真

结果将是一个函数,该函数从第一张图片获取X,Y点,并返回与第二张图片上完全相同的Point相对应的X',Y'.

The result will be a function getting X,Y Point from first picture and returning X',Y' corresponding to the exact same Point on the second picture.

我支持OpenCV的findHomography()函数,该函数返回Homography矩阵,但在所有示例中,该矩阵都用于通过warpPerspective()扭曲第二张图像,这不是我想要的.我只想要两张图片之间的相应坐标/像素.

I foud OpenCV's findHomography() function which return a Homography matrix but in all the examples this matrix is used to distort the second image with warpPerspective() which is not what I want. I just want the corresponding coordinates / pixels between the two pictures.

有关如何在C#中执行此操作的任何提示? (是否使用OpenCV)

Any tips on how to do that in C# ? (With OpenCV or not)

要点示例:

普通图片:[250,25],[250,287],[399,287],[400,28]

Normal picture : [250, 25] , [250, 287] , [399, 287] , [400, 28]

目标图片:[0,0],[2098,29538],[19127,28164],[17097,-1200]

Target picture : [0, 0] , [2098, 29538] , [19127, 28164] , [17097, -1200]

使用OPEN CV

OpenCvSharp.Mat hCv = OpenCvSharp.Cv2.FindHomography(srcPoints, dstPoints);
OpenCvSharp.Point2d[] resultCv = OpenCvSharp.Cv2.PerspectiveTransform(targetCv, hCv);

推荐答案

感谢Alexander Reynolds的评论,我终于使用了 OpenCvSharp 3 库. 您可以使用以下方法获得单应性矩阵:

Thanks to Alexander Reynolds comment, I finally used the OpenCvSharp 3 library. You get the homography matrix using:

homographyMatrix = OpenCvSharp.Cv2.FindHomography(originalPicturePoints, targetPicturePoints);

,然后从原始图片中获取目标图片上的任何点:

and then to get any point on the target picture from the original picture:

targetPoint = OpenCvSharp.Cv2.PerspectiveTransform(orignalPoint, homographyMatrix);

这篇关于使用Homography链接两个图片像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆