旋转目标检测中常常需要用opencv的cv2.boxPoints()画旋转框,但是具体输出和图中四个顶点坐标是如何对应的,需要研究一下。
opencv中图片左上角是(0,0),旋转框定义为[x,y,w,h,theta],角度theta是指框与x轴所组成的锐角,并且框的这条边记为w,另一条边记为h,角度范围[-90,0)。
代码片段:
# 中心点坐标(x_c,y_c) 宽w 高h 旋转角度theta
# 最小外接矩形,返回八个坐标值(x1,y1) (x2,y2) (x3,y3) (x4,y4)
rect = cv2.boxPoints((x_c,y_c),(w,h),theta)
rect = np.int0(rect) # 取整
# 右下角坐标(x1,y1)
coordinate1 = rect[0]
# 左下角坐标(x2,y2)
coordinate1 = rect[1]
# 左上角坐标(x3,y3)
coordinate1 = rect[2]
# 右上角坐标(x4,y4)
coordinate1 = rect[3]