bb:=90
tuple_rad (bb, Rad)
threshold (Image, Region, 87, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 140400, 295000)
region_features (SelectedRegions, 'area', Value)
region_
gen_contour_region_xld (SelectedRegions, Contours, 'border')
fit_rectangle2_contour_xld (Contours, 'tukey', -1, 0, 2, 3, 1, Row3, Column3, Phi2, Length11, Length21, PointOrder)
gen_region_contour_xld (Contours, Region2, 'filled')
tuple_length(Row3,Length)
for Index := 0 to Length-1 by 1
dev_display (Image)
Length1:= Length11[Index]
Length2:=Length21[Index]
Phi1:=Phi2[Index]
if(abs(deg(Phi2[Index]))>45)
Phi1:=rad(deg(Phi2[Index])-90*(Phi2[Index]/abs(Phi2[Index])))
Tmp:=Length11[Index]
Length1:= Length21[Index]
Length2:=Tmp
endif
tuple_sin (Phi1, Sin)
tuple_cos (Phi1, Cos)
*左上角
TopLeft_X := -Length1*Cos - Length2*Sin
TopLeft_Y := -Length1*Sin + Length2*Cos
TopLeft_Row := Row3[Index] - TopLeft_Y
TopLeft_Col := Column3[Index] + TopLeft_X
*右上角
TopRight_X := Length1*Cos - Length2*Sin
TopRight_Y := Length1*Sin + Length2*Cos
TopRight_Row := Row3[Index] - TopRight_Y
TopRight_Col := Column3[Index] + TopRight_X
*右下角
LowerRight_X := Length1*Cos + Length2*Sin
LowerRight_Y := Length1*Sin - Length2*Cos
LowerRight_Row := Row3[Index] - LowerRight_Y
LowerRight_Col := Column3[Index] + LowerRight_X
*左下角
LowerLeft_X := -Length1*Cos + Length2*Sin
LowerLeft_Y := -Length1*Sin - Length2*Cos
LowerLeft_Row := Row3[Index] - LowerLeft_Y
LowerLeft_Col := Column3[Index] + LowerLeft_X
row:=[TopLeft_Row,TopRight_Row,LowerRight_Row,LowerLeft_Row,TopLeft_Row]
col:=[TopLeft_Col,TopRight_Col,LowerRight_Col,LowerLeft_Col,TopLeft_Col]
gen_contour_polygon_rounded_xld (Contour, [TopLeft_Row,TopRight_Row,LowerRight_Row,LowerLeft_Row,TopLeft_Row], [TopLeft_Col,TopRight_Col,LowerRight_Col,LowerLeft_Col,TopLeft_Col], [0,0,0,85,0], 1)
gen_region_contour_xld (Contour, Region1, 'filled')
difference (Region2, Region1, RegionDifference)
connection (RegionDifference, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 1000, 99999)
wait_seconds (6)
endfor