2021年3月3日星期三

Is there any ways to write some images in a folder with cv2.write using Python?

I have already write a code like this for sharpening filter of many images in a folder :
code

Sharpen filter

import cv2
import glob
import numpy as np
import matplotlib.pyplot as plt

images1_src = [cv2.imread(file) for file in glob.glob('/content/drive/MyDrive/Colab Notebooks/cars/car/*.png')]
kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])


kernel = kernel/sum(kernel)
sharpen = cv2.filter2D(images1_src, -1, kernel)
for n in range(0, len(images1_src)):

images[n] = cv2.imread(join('/content/drive/MyDrive/Colab Notebooks/cars/car/*.png', images1_src[n]))

cv2.imwrite(f'/content/drive/MyDrive/Colab Notebooks/cars/car/image_{n}.png', images1_src)
cv2.waitKey(0)


And the result is error :
result code



---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
11
12 kernel = kernel/sum(kernel)
---> 13 sharpen = cv2.filter2D(images1_src, -1, kernel)
14 for n in range(0, len(images1_src)):
15 images[n] = cv2.imread(join('/content/drive/MyDrive/Colab Notebooks/cars/car/*.png', images1_src[n]))

TypeError: Expected Ptr<cv::UMat> for argument '%s'

https://stackoverflow.com/questions/66467559/is-there-any-ways-to-write-some-images-in-a-folder-with-cv2-write-using-python March 04, 2021 at 10:05AM

没有评论:

发表评论