.COLOR_BGR2GRAY)
ret,thresh=cv2.threshold(img,230,255,cv2.THRESH_BINARY_INV)
contours,hierarchy=cv2.findContours...(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
dot=[]
for c in contours:
#检测边界坐标
min_list...=[]#保存单个轮廓的信息,x,y,w,h,area,x,y为起始点坐标
x,y,w,h=cv2.boundingRect(c)#计算点集最外面的矩形边界
min_list.append...region=result.crop((x,y,x+w,y+h))
region.save('C:/Users/xpp/Desktop/result.png')
cv2.waitKey(0)
算法:图像主体裁剪是选取图像中面积最大轮廓...,绘制矩形框,裁剪目标区域。