def getMask(self, shape):
p=self.state['pos']
s=self.state['size']
center=p + s / 2
a=self.state['angle']
# opencv convention:
shape = (shape[1], shape[0])
arr1 = np.zeros(shape, dtype=np.uint8)
arr2 = np.zeros(shape, dtype=np.uint8)
# draw rotated rectangle:
vertices = np.int0(cv2.boxPoints((center, s, a)))
cv2.drawContours(arr1, [vertices], 0, color=1, thickness=-1)
# draw ellipse:
cv2.ellipse(arr2, (int(center[0]), int(center[1])), (int(s[0] / 2 * self._ratioEllispeRectangle),
int(s[1] / 2 * self._ratioEllispeRectangle)), int(a),
startAngle=0, endAngle=360, color=1, thickness=-1)
# bring both together:
return np.logical_and(arr1, arr2).T
评论列表
文章目录