OpenCV经向 [英] OpenCV warpperspective

查看:387
本文介绍了OpenCV经向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,每当我使用OpenCV的warpPerspective()函数时,最终的变形图像不包含原始图像中的所有内容。图像的左边部分似乎被切断。我认为发生这种情况的原因是因为翘曲的图像是在warpPerspective()的画布的最左边位置创建的。有没有办法解决这个问题?感谢

For some reason whenever I use OpenCV's warpPerspective() function, the final warped image does not contain everything in the original image. The left part of the image seems to get cut off. I think the reason why this is happening is because the warped image is created at the leftmost position of the canvas for the warpPerspective(). Is there some way to fix this? Thanks

推荐答案

出现问题是因为单应性将图像的一部分映射到图像区域之外的负x,y值无法绘制。
我们希望做的是将翘曲的输出偏移某个数量的像素,以将整个翘曲的图像分流为正坐标(因此在图像区域内)。

The problem occurs because the homography maps part of the image to negative x,y values which are outside the image area so cannot be plotted. what we wish to do is to offset the warped output by some number of pixels to 'shunt' the entire warped image into positive coordinates(and hence inside the image area).

同形可以使用矩阵乘法(这就是为什么它们是如此强大)。如果A和B是单应性,则AB表示首先应用B的单应性,然后是A。

Homographies can be combined using matrix multiplication (which is why they are so powerful). If A and B are homographies, then AB represents the homography which applies B first, and then A.

因为这一切,我们需要做的是偏移输出是create然后通过我们的原始单应性矩阵对其进行预乘。

Because of this all we need to do to offset the output is create the homography matrix for a translation by some offset, and then pre-multiply that by our original homography matrix

2D单应性矩阵看起来像这样:

A 2D homography matrix looks like this :

[R11,R12,T1]
[R21,R22,T2]
[ P , P , 1]

其中R表示旋转矩阵,T表示平移,P表示透视变形。
因此,纯粹的翻译单应性看起来像这样:

where R represents a rotation matrix, T represents a translation, and P represents a perspective warp. And so a purely translational homography looks like this:

[ 1 , 0 , x_offset]
[ 0 , 1 , y_offset]
[ 0 , 0 ,    1    ]

(确保使用矩阵乘法,而不是元素乘法!)

(Make sure you use matrix multiplication, not element wise multiplication!)

这篇关于OpenCV经向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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