错误在Python 3.6.4中的Opencv 3

时间:2018-05-02 06:01:50

标签: python opencv module

我刚刚开始在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控制台上运行代码 但什么都没发生。 请帮忙

2 个答案:

答案 0 :(得分:3)

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

  

该功能 warpAffine wrapAffine

答案 1 :(得分:2)

  wrapAffine(image, T, (width, height))

该功能为warpAffine。 此功能将仿射变换应用于图像