python用opencv批量截取图像指定区域

代码如下

import os
import cv2
for i in range(1,201):
    if i==169 or i==189:
        i = i+1
    pth = "C:\\Users\\Desktop\\asd\\"+str(i)+".bmp"
    image = cv2.imread(pth)            //从指定路径读取图像
    cropImg = image[600:1200,750:1500] //获取感兴趣区域
    cv2.imwrite("C:\\Users\\Desktop\\qwe\\"+str(i)+".bmp",cropImg) //保存到指定目录
   # print pth
#cropImg = image[100:200, 100:200]
#cv2.imwrite("a.bmp",cropImg)

你可能感兴趣的:(人工智能学习笔记)