python+opencv 读取文件夹下的所有图像并批量保存ROI

[python]  view plain  copy
  1. import cv2  
  2. import os  
  3.   
  4. import numpy as np  
  5.   
  6. root_path = "I:/Images/2017_08_03/"  
  7. dir = root_path+"images"+"/"  
  8. count = 0  
  9. for root,dir,files in os.walk(dir):  
  10.     for file in files:  
  11.         srcImg = cv2.imread(root_path+"images"+"/"+str(file))  
  12.         roiImg = srcImg[36:521180:745]  
  13.         cv2.imwrite(root_path+"Image"+"/"+str(file),roiImg)  
  14.         count +=1  
  15.         if count%400==0:  
  16.             print count  

你可能感兴趣的:(python学习,毕业设计,OpenCV)