接续上一篇Halcon——点胶机胶水路径应用(1):
https://blog.csdn.net/weixin_38566632/article/details/121181385
TranslationX1:=120 //左移动距离
TranslationX2:=60 //右移动距离
Voaid1:=50 //上避让距离
Voaid2:=90 //下避让距离
GluePointR:=[]
GluePointC:=[]
list_files ('', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
* 电池主体区域最小外接矩形
GetCellBody (Image, Rectangle)
* 计算点胶起点和终点
GetGluePoints (Rectangle, TranslationX1, Voaid1, TranslationX2, Voaid2, GluePointR, GluePointC)
dev_set_color ('green')
dev_display (Image)
gen_cross_contour_xld (crosses, GluePointR, GluePointC, 96, 0)
disp_message (3600, '1', 'image', GluePointR[0], GluePointC[0], 'green', 'false')
disp_message (3600, '2', 'image', GluePointR[1], GluePointC[1], 'green', 'false')
disp_message (3600, '3', 'image', GluePointR[2], GluePointC[2], 'green', 'false')
disp_message (3600, '4', 'image', GluePointR[3], GluePointC[3], 'green', 'false')
dev_display (crosses)
stop()
endfor
GetCellBody
* ==================得到电池区域最小外接矩形==========================
gen_rectangle1 (ROI_0, 526.525, 1306.97, 3622.8, 4252.81)
reduce_domain (Image, ROI_0, ImageReduced)
threshold (ImageReduced, Regions, 0, 250)
fill_up (Regions, RegionFillUp)
gen_contour_region_xld (RegionFillUp, Contours, 'border')
segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 5, 30, 5)
select_shape_xld (ContoursSplit, SelectedXLD, ['contlength','height'], 'and', [753.82,1071.88], [4557.89,4799.62])
gen_region_contour_xld (SelectedXLD, Region, 'filled')
union1 (Region, RegionUnion)
smallest_rectangle2 (RegionUnion, Row, Column, Phi, Length1Org, Length2Org)
gen_rectangle2 (Rectangle1, Row, Column, Phi, Length1Org, Length2Org)
return()
GetGluePoints
* ==================计算点胶位置==========================
smallest_rectangle2 (Rectangle, Row, Column, Phi, Length1Org, Length2Org)
* 左上角点
Length2:=Length2Org - TranslationX1
Length1:=Length1Org-Voaid1
gen_rectangle2_contour_xld (Rectangle1,Row, Column, Phi, Length1, Length2)
if (Phi < 0)
Phi:=rad(180)+Phi
endif
tuple_cos (Phi, Cos)
tuple_sin (Phi, Sin)
X := Length1*Cos - Length2*Sin
Y := Length1*Sin + Length2*Cos
gen_cross_contour_xld(Cross2, Row-Y, Column+X, 96, 0)
GluePointR[0]:=Row-Y
GluePointC[0]:=Column+X
* 右上角点
Length2:=Length2Org - TranslationX2
Length1:=Length1Org-Voaid1
gen_rectangle2_contour_xld (Rectangle1,Row, Column, Phi, Length1, Length2)
if (Phi < 0)
Phi:=rad(180)+Phi
endif
tuple_cos (Phi, Cos)
tuple_sin (Phi, Sin)
X := Length1*Cos + Length2*Sin
Y := Length1*Sin - Length2*Cos
* gen_cross_contour_xld(Cross3, Row-Y, Column+X, 96, 0)
GluePointR[1]:=Row-Y
GluePointC[1]:=Column+X
* 左下角点
Length2:=Length2Org - TranslationX1
Length1:=Length1Org-Voaid2
* gen_rectangle2_contour_xld (Rectangle1,Row, Column, Phi, Length1, Length2)
X := -Length1*Cos - Length2*Sin
Y := -Length1*Sin + Length2*Cos
* gen_cross_contour_xld(Cross1, Row-Y, Column+X, 96, 0)
GluePointR[2]:=Row-Y
GluePointC[2]:=Column+X
* 右下角点
Length2:=Length2Org - TranslationX2
Length1:=Length1Org-Voaid2
gen_rectangle2_contour_xld (Rectangle1,Row, Column, Phi, Length1, Length2)
X := -Length1*Cos + Length2*Sin
Y := -Length1*Sin - Length2*Cos
* gen_cross_contour_xld(Cross4, Row-Y, Column+X, 96, 0)
GluePointR[3]:=Row-Y
GluePointC[3]:=Column+X
return ()
https://download.csdn.net/download/weixin_38566632/43599312