python透视变换原理_Python中的OpenCV透视变换

使用Python的OpenCV库进行图像透视变换时遇到错误。尝试使用cv2.perspectiveTransform()函数,但输入图像必须为浮点数类型。解决方法是将8位无符号整型图像转换为适当的浮点数据类型。

I'm trying to rectify an image in python. I have a Homography H (from a rotation matrix that rotates around the x, y and z axis) that looks like this for example:

[[ 9.95671447e-01 7.83610423e-02 7.47993630e+02]

[ -7.69292630e-02 9.96586377e-01 -4.48354859e+02]

[ -3.48494755e-06 1.73615469e-06 9.98300856e-01]]

I thought I could do this woth cv2.perspectiveTransform() but I cant't get it to work. This is the code I use:

# warp image

img_cv2 = cv2.imread('surf.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)

# strange output but it does something:

dst = cv2.perspectiveTransform(img_cv2,H)

But I get the following error:

Traceback (most recent call last):

File "C:\directory structure\python_files\Rectification\rectify.py", line 82, in

dst = cv2.perspectiveTransform(img_cv2,H)

error: C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\matmul.cpp:1916: error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)`

Can anybody see what is going wrong?

解决方案

The source and destination image must be floating point data.

cv2.perspectiveTransform(src, m[, dst]) → dst

Parameters:

src – input two-channel or three-channel floating-point array; each element is a 2D/3D vector to be transformed.

dst – output array of the same size and type as src.

m – 3x3 or 4x4 floating-point transformation matrix.

So convert the 8U image to the appropriate datatype.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值