我正在尝试从以下网站运行一个放大图像的示例: https ://towardsdatascience.com/deep-learning-based-super-resolution-with-opencv-4fd736678066
这是我正在使用的代码:
import cv2
from cv2 import dnn_superres
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read image
image = cv2.imread('butterfly.png')
# Read the desired model
path = "EDSR_x3.pb"
sr.readModel(path)
# Set the desired model and scale to get correct pre- and post-processing
sr.setModel("edsr", 3)
# Upscale the image
result = sr.upsample(image)
# Save the image
cv2.imwrite("./upscaled.png", result)
我从网站下载了已经训练好的模型,名为“EDSR_x3.pb”,当我运行代码时,我收到以下错误:
Traceback (most recent call last):
File "upscale.py", line 2, in <module>
from cv2 import dnn_superres
ImportError: cannot import name 'dnn_superres'
我现在似乎没有这样的方法或类,但我已经安装了 opencv 和 contrib 模块。为什么我会收到此错误?