Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 调整文件夹中所有图像的大小_Python_Python 3.x_Image Resizing_Cv2 - Fatal编程技术网

Python 调整文件夹中所有图像的大小

Python 调整文件夹中所有图像的大小,python,python-3.x,image-resizing,cv2,Python,Python 3.x,Image Resizing,Cv2,我正在创建一个小路径,以将所有调整大小的图像从“测试目录”保留为“小” 一切似乎都很好,请帮助我解码它假设以下代码正常工作: import numpy as np import cv2 import os if not os.path.exists('small'): os.makedirs('small') pic_num=1 for i in ['test']: try: if os.path.exists(str(pic_num)+'.jpg'): p

我正在创建一个小路径,以将所有调整大小的图像从“测试目录”保留为“小”
一切似乎都很好,请帮助我解码它

假设以下代码正常工作:

import numpy as np
import cv2
import os 

if not os.path.exists('small'):
   os.makedirs('small')
pic_num=1   

for i in ['test']:

 try:
  if os.path.exists(str(pic_num)+'.jpg'):
      print(i)
      img=cv2.imread(str(pic_num)+'.jpg')
      resized_image=cv2.resize(img,(100,100))
      cv2.imwrite("small/"+str(pic_num)+'.jpg',resized_image)
  pic_num+=1 
 except Exception as e:
      print(str(e))

假设以下代码正在工作:

import numpy as np
import cv2
import os 

if not os.path.exists('small'):
   os.makedirs('small')
pic_num=1   

for i in ['test']:

 try:
  if os.path.exists(str(pic_num)+'.jpg'):
      print(i)
      img=cv2.imread(str(pic_num)+'.jpg')
      resized_image=cv2.resize(img,(100,100))
      cv2.imwrite("small/"+str(pic_num)+'.jpg',resized_image)
  pic_num+=1 
 except Exception as e:
      print(str(e))