裁剪遥感影像--制作数据集

匿名 (未验证) 提交于 2019-12-02 23:37:01
 import os from PIL import Image import cv2 import time  file_dir = '.' files = os.listdir(file_dir)  na = 0 for file in files:       if os.path.isfile(file):         # img = Image.open(file)         img = cv2.imread(file)         long = img.shape[0]         width = img.shape[1]         upper = 0         lower = 0         kj = 0          while lower + 16 < width:              left = 0             upper = (16*kj)             right = 16             lower = 16*(kj+1)             kj +=1             print(left, upper, right, lower)             ki = 0              while right + 16 <long:                 left = ki * 16                 right = 16 + ki * 16                 ki +=1                 newImg = img[upper:lower-1,left:right-1]                 na = str(na)                 # newImg.save("/home/ly/Documents/program/RGB-Water/Edata/"+na+".jpg")                 cv2.imwrite("/home/ly/Documents/program/RGB-Water/Edata/"+na+".jpg",newImg)                 na = int(na)                 na +=1                 print(left, upper, right-1, lower-1)                 # time.sleep(1)                 #Image._show(img) 

文章来源: https://blog.csdn.net/dahuayaoer/article/details/90751704
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!