python - 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 控制台上运行代码,但什么也没发生。请帮忙
解决方案
您的代码中有拼写错误,或者可能是对正确术语的误解。
函数是
warpAffine
,不是wrapAffine
。
推荐阅读
- excel - 如何在 Excel 单元格中替换字符并删除 no
- python - 使用 dict 数据类型创建嵌套循环
- python - 我无法按计划将数据写入 csv
- uwp - 我无法获得正确的 StoreContext
- sql - 这个“Where”条件会加速 SQL 查询吗
- apache-spark - KubernetesPodOperator 未按预期发送参数
- kotlin - 如何在 IntelliJ 中不使用 gradle 来执行 Kotlin main
- flutter - 如何将选中的 List Tile 中的数据传递到 Flutter 中的下一页(篮子)
- python - 将 ode45 代码从 MATLAB 转换为 python 代码
- python - 如何使用现有数据库覆盖 Django 中的 M2M 字段名称和模型?