cv2.boundingRect和cv2.fillPol 用多边形填充图形:
pts:提取出来的特征点 转为np.array->astype(dtype=int)->reshape(-1,1,2)
///boundingRec返回正矩形
/// minAreaRect返回最小斜矩形
x,y,w,h:返回矩形框的x,y,w,h
newImg = np.full(img.shape, 255, dtype=np.uint8)
创建一个背景图
cv2.fillPoly(newImg, [pts], 0)
多边形填充pts并放入newimg中
split_img = np.full(img.shape, 255, dtype=np.uint8)
创建一个背景图
split_img[newImg==0] = img[newImg==0]
split_Img为 img大小的白色背景和 fillpoy后newimg大小的黑色填充图形的图片
split_img = split_img[y:y+h, x:x+w]
在原split_img中截取填充大小的图片为所需图片