我有4个坐标: x1,y1 x2,y2 x3,y3 x4,y4
我无法使用opencv从多个坐标中提取图像。 如何使其工作?如何只提取被遮罩的区域?
import numpy as np
import cv2
contours= 4, 429, 0, 386, 67, 368, 78, 411
file_path = "img_10.jpg"
# read image
img = cv2.imread(file_path, 1)
arr = np.array(contours).reshape(4, 2)
arr_points = np.array(arr, dtype=np.int32)
mask = np.zeros((img.shape[0], img.shape[1]))
cv2.fillConvexPoly(mask, arr_points, 1)
mask = mask.astype(np.bool)
out = np.zeros_like(img)
out[mask] = img[mask]
cv2.imwrite('output.png', out)