#prepare degraded images by introducing quality distortion by resizing images
def prepare_images(factor):
path = './SRCNN/source'
#loop through the file in the directory
for files in os.listdir(path):
#open the file
img = cv2.imread(path + '/' + files)
#find old and new image dimaensions
h, w, c = img.shape
new_height = h /factor
new_width = w / factor
#resize the image - down
img = (cv2.resize(img, (int(new_width), int(new_height)), interpolation=cv2.INTER_LINEAR))
#resize the image - up
img = (cv2.resize(img, (w, h), interpolation = INTER_LINEAR))
# save the image
print('Saving {}'.format(files))
cv2.imwrite('images/{}'.format(files), img)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-77-6ba532c6503e> in <module>()
----> 1 prepare_images(2)
2 #os.listdir('./SRCNN/source')
<ipython-input-76-4a7882c5ab03> in prepare_images(factor)
16
17 #resize the image - up
---> 18 img = (cv2.resize(img, (w, h), interpolation = INTER_LINEAR))
19
20 # save the image
NameError: name 'INTER_LINEAR' is not defined
第一部分是函数。第二部分是该函数的错误。我如何解决这个问题?我是在Google Colab上写的这段代码,也在Jupyter上试过......
为了使用 INTER_LINEAR
所以你可以添加一个导入。
from cv2 import INTER_LINEAR
或者
变化 interpolation = INTER_LINEAR
将要 interpolation = cv2.INTER_LINEAR