首页 > 解决方案 > python 3.6.4中的错误Opencv 3

问题描述

我刚开始在 python 上学习 opencv 我想运行这段代码时使用的是 win 10、python 3.6.4 和 opencv 3.4

image = cv2.imread("lena.jpg")

height, width = image.shape[:2]

quarter_height, quarter_width = height/4, width/4

T = np.float32([[1, 0, quarter_height], [0, 1, quarter_width]])
img_translation = cv2.wrapAffine(image, T, (width, height))
cv2.imshow("Translate", img_translation)
cv2.waitKey(0)
cv2.destroyAllWindows()

引发此错误

Traceback (most recent call last):
File "C:\...\PyCharm 2018.1.2\helpers\pydev\pydev_run_in_console.py", line 
52, 
in run_file
pydev_imports.execfile(file, globals, locals)  # execute the script
File "C:\...\PyCharm 2018.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", 
line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Projects/P03/Program.py", line 20, in <module>
main()
File "C:/Projects/P03/Program.py", line 13, in main
img_translation = cv2.wrapAffine(image, T, (width, height))
AttributeError: module 'cv2.cv2' has no attribute 'wrapAffine'

但是当我在 dir(cv2) 中看到时,我可以找到 wrapAffine 函数

我确实知道如何解决这个问题,我尝试在几个 IDE 和 python 控制台上运行代码,但什么也没发生。请帮忙

标签: pythonopencvmodule

解决方案


您的代码中有拼写错误,或者可能是对正确术语的误解。

函数是warpAffine不是 wrapAffine


推荐阅读