在 openCV 中一次对多张图像应用调整大小 python
Apply resize on multiple images at one time in openCV python
我已经使用 glob 和 imread 读取了一个包含图片的文件夹。现在我想在 cv2.resize.
中使用 for 循环调整所有这些图片的大小
以下是我的代码,但输出不正确--
import cv2
import glob
path = glob.glob("C:/Users/RX-91-9/Desktop/prescriptions/*.jpg")
for file in (path):
img=cv2.imread(file)
cv2.imshow("Image", img)
cv2.cv2.waitKey(3)
cv2.destroyAllWindows()
for i in img:
resized_image = cv2.resize(i, (1600,1600))
cv2.imshow('resized_image', resized_image)
cv2.waitKey(3)
cv2.destroyAllWindows()
我不知道为什么最后一个 for 循环没有给出预期的输出,我想调整 'img' 中所有图像的大小。如果您发现我的 for last for 循环有什么问题,请帮忙。
我假设您在某个文件夹中有一个图像列表,并且您要调整所有图像的大小。你可以运行
import cv2
import glob
for filename in glob.glob('images/*.jpg'): # path to your images folder
print(filename)
img=cv2.imread(filename)
rl=cv2.resize(img, (500,500))
cv2.imwrite(f'{filename}resized.jpg', rl)
我已经使用 glob 和 imread 读取了一个包含图片的文件夹。现在我想在 cv2.resize.
中使用 for 循环调整所有这些图片的大小以下是我的代码,但输出不正确--
import cv2
import glob
path = glob.glob("C:/Users/RX-91-9/Desktop/prescriptions/*.jpg")
for file in (path):
img=cv2.imread(file)
cv2.imshow("Image", img)
cv2.cv2.waitKey(3)
cv2.destroyAllWindows()
for i in img:
resized_image = cv2.resize(i, (1600,1600))
cv2.imshow('resized_image', resized_image)
cv2.waitKey(3)
cv2.destroyAllWindows()
我不知道为什么最后一个 for 循环没有给出预期的输出,我想调整 'img' 中所有图像的大小。如果您发现我的 for last for 循环有什么问题,请帮忙。
我假设您在某个文件夹中有一个图像列表,并且您要调整所有图像的大小。你可以运行
import cv2
import glob
for filename in glob.glob('images/*.jpg'): # path to your images folder
print(filename)
img=cv2.imread(filename)
rl=cv2.resize(img, (500,500))
cv2.imwrite(f'{filename}resized.jpg', rl)