Halcon可以通过最小外接矩型算子获取Retangle2的中心点坐标,角度,半长,半宽。但是却没有四个顶点坐标和四个线段中点坐标。下面的代码是获取四个顶点坐标和四个线段中点坐标的方法。
gen_rectangle2 (Rectangle, 300, 200, 0.39, 100, 50)
CenterX:=200
CenterY:=300
JXPhi:=0.39
Len1:=100
Len2:=50
*矩形端点坐标变量,变中心坐标变量初始化
CornerX:=[]
CornerY:=[]
LineCenterY:=[]
LineCenterX:=[]
*临时变量初始化
RowT:=0
ColT:=0
*判断仿射矩形是否有效
if (Len1<=0 or Len2<=0)
return ( )
endif
*计算仿射矩形角度的正弦,余弦
tuple_cos(JXPhi,Cos)
tuple_sin(JXPhi,Sin)
*矩形第一个端点
ColT:=CenterX-Len1*Cos-Len2*Sin
RowT:=CenterY-(-Len1*Sin+Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第二个端点
ColT:=CenterX+Len1*Cos-Len2*Sin
RowT:=CenterY-(Len1*Sin+Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第三个端点
ColT:=CenterX+Len1*Cos+Len2*Sin
RowT:=CenterY-(Len1*Sin-Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第四个端点
ColT:=CenterX-Len1*Cos+Len2*Sin
RowT:=CenterY-(-Len1*Sin-Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
dev_set_color ('white')
gen_cross_contour_xld (Cross, CornerY, CornerX, 10, 0.785398)
*矩形第一条边中心坐标
LineCenterY[0]:=(CornerY[0]+CornerY[1])*0.5
LineCenterX[0]:=(CornerX[0]+CornerX[1])*0.5
*矩形第二条边中心坐标
LineCenterY[1]:=(CornerY[1]+CornerY[2])*0.5
LineCenterX[1]:=(CornerX[1]+CornerX[2])*0.5
*矩形第三条边中心坐标
LineCenterY[2]:=(CornerY[3]+CornerY[2])*0.5
LineCenterX[2]:=(CornerX[3]+CornerX[2])*0.5
*矩形第四条边中心坐标
LineCenterY[3]:=(CornerY[3]+CornerY[0])*0.5
LineCenterX[3]:=(CornerX[3]+CornerX[0])*0.5
dev_set_color ('blue')
gen_cross_contour_xld (Cross1, LineCenterY, LineCenterX, 10, 0.785398)
return()