python opencv 在大图中随机裁剪等大子区域

import cv2
import random

img_none=cv2.imread('none.jpg')# 大图
print(img_none.shape) 
#(4244, 3228, 3) = (height,width,channel)
# 子区域 宽182,高428
a=3228-182
b=4244-428
for i in range(40): # 取40个子区域 
   x=random.randint(0, b)
   y=random.randint(0, a)
   print('({},{})'.format(x,y))
   res=img_none[x:x+428,y:y+182] #子区域
cv2.imwrite('./img_save/none/mush_none_'+str(i)+'.jpg',res)

猜你喜欢

转载自blog.csdn.net/a272881819/article/details/121979255