小编Lil*_*lly的帖子

如何修复“错误:模块‘cv2’在 python 3.7.9 和 Windows 11 上没有属性‘legacy’”?

我安装了OpenCV 4.5.2.52 版本,尝试对我想阅读但太模糊的图片使用超分辨率。

为此,我遵循此站点中的代码: https: //programmer.group/opencv-advanced-super-resolution-based-on-opencv.html

我可以复制此页面上的不同代码,我想尝试一下这个:

import cv2
import matplotlib.pyplot as plt

# Read picture
img = cv2.imread("AI-Courses-By-OpenCV-Github.png")
img = img[5:60,700:755]
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "ESPCN_x3.pb"
sr.readModel(path)
sr.setModel("espcn",3)
result = sr.upsample(img)

# Resize image
resized = cv2.resize(img,dsize=None,fx=3,fy=3)
plt.figure(figsize=(6,2))
plt.subplot(1,3,1)

# original image 
plt.imshow(img[:,:,::-1])
plt.subplot(1,3,2)

# SR up sampling image
plt.imshow(result[:,:,::-1])
plt.subplot(1,3,3)

## Sampling images on OpenCV
plt.imshow(resized[:,:,::-1])
plt.show()
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到错误“ AttributeError:模块'cv2'没有属性'dnn_superres' ”。所以我检查了这些页面“https://blog.csdn.net/qq_48455792/article/details/120258336”(翻译自中文)和“https://github.com/opencv/opencv-python/issues/441”其中据报道,对于 4.5.x 以上的 openCV 版本,库已移至“旧版”。

我明白我只需要改变sr = cv2.dnn_superres.DnnSuperResImpl_create()它就sr = cv2.legacy.dnn_superres.DnnSuperResImpl_create()可以工作。

但随着这个改变我得到了错误 AttributeError: …

python legacy opencv attributeerror

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

attributeerror ×1

legacy ×1

opencv ×1

python ×1