从给定坐标扭曲图像-OpenCV Python



我现在正在学习OpenCV。这个练习的目标是从铺设的角度获得扑克卡的4个角点,并将其在你面前压平。

正如你所看到的,我已经在pts1/角上正确分配了坐标(至少在检查后是这样(。

输出imgWarped后,抛出错误:

traceback (most recent call last):
File "C:UsersdracoPycharmProjectsReadermain.py", line 101, in <module>
imgWarped = cv2.warpPerspective(img,matrix,(width,height))
cv2.error: OpenCV(4.4.0) C:UsersappveyorAppDataLocalTemp1pip-req-build-95hbg2jtopencvmodulesimgprocsrcimgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function 'cv::warpPerspective'

网上的文件并没有帮我解决这个问题。我的错误消息实际上意味着什么?它是如何发生的?有更好的练习吗?

这是代码:

import cv2
import numpy as np
img = cv2.imread("Resources/cards.jpg")
width,height = 250,350
pts1 = np.float32([[124,161],[189,155],[200,231],[135,245]])
pts2 = np.float32([[0,0],[width,0],[width,height],[0,height]])
matrix = cv2.getPerspectiveTransform(pts1,pts2)
---Here is the error --> imgWarped = cv2.warpPerspective(img,matrix,(width,height))

cv2.imshow("Warped Img", imgWarped)
cv2.waitKey(0)

我使用了您的代码和我自己的图像来重新生成错误,但效果很好。你可以向我们发布你的输入图像,或者确保你选择的点不大于你的图像本身,因为我可以看到你正在对点进行硬编码

最新更新