原图
找到电池主体
找到放置抓边工具的位置
抓边
计算胶水路径
带有角度1
带有角度2
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])
rgb1_to_gray (Image, GrayImage)
dev_set_line_width (2)
* 1. 分割电池主体部分
GetCellBody (GrayImage, Rectangle)
dev_display (GrayImage)
dev_display (Rectangle)
stop()
* 2. 计算角点 左上角点作为起点,逆时针排列
GetCornerPoints (GrayImage, Rectangle, CornerRow, CornerCol)
gen_cross_contour_xld (Cross, CornerRow, CornerCol, 150, 0)
dev_display (GrayImage)
dev_display (Cross)
stop()
* 3. 边缘测量 求交点
Elements:=20
DetectHeight:=150
DetectWidth:=5
Sigma:=3
Threshold:=30
Transition:='all'
Select:='all'
ActiveNum:=5
GetIntersetcionPoints (GrayImage, Line1, Line2, Line3, Line4, \
Elements, DetectHeight, DetectWidth, Sigma, Threshold, Transition, Select,\
CornerRow, CornerCol, ActiveNum, Row1, Column1, Row2, Column2, Row3, Column3, Row4, Column4)
dev_display (GrayImage)
dev_set_color ('green')
dev_display (Line1)
dev_display (Line2)
dev_display (Line3)
dev_display (Line4)
stop()
* 4. 将边缘线沿着垂线方向向电芯内侧平移
TranslationX:=150 //控制点胶线径向方向的移动距离
Avoid1:=100 //控制点胶线切向方向的移动距离1
Avoid2:=300 //控制点胶线切向方向的移动距离2
GetGluePoints (Line1, Line2, Glue1, Glue2, TranslationX, Avoid1, Avoid2, Row1, Column1, Row2, Column2, Row3, Column3, Row4, Column4, RowNew1, ColumnNew1, RowNew2, ColumnNew2, RowNew3, ColumnNew3, RowNew4, ColumnNew4)
dev_display (GrayImage)
dev_set_color ('red')
dev_display (Glue1)
dev_set_color ('green')
dev_display (Glue2)
stop()
endfor
threshold (GrayImage, Regions1, 0, 83)
connection (Regions1, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2.74491e+006, 5e+006)
opening_rectangle1 (SelectedRegions, RegionOpening, 400, 400)
smallest_rectangle2 (RegionOpening, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
return ()
get_image_size (GrayImage, Width, Height)
gen_image_const (Image1, 'byte', Width, Height)
paint_region (Image1, Image1, ImageResult, 255, 'fill')
paint_region (Rectangle, ImageResult, ImageResult, 0, 'fill')
points_foerstner (ImageResult, 1, 2, 3, 200, 0.1, 'gauss', 'false', \
RowJunctions, ColumnJunctions, CoRRJunctions, CoRCJunctions,\
CoCCJunctions, RowArea, ColumnArea, CoRRArea, CoRCArea, CoCCArea)
* 角点排序 检测角点是从上向下逐行检测的 排序是从左上角点开始,从左到右,从上到下
CornerRow:=[]
CornerCol:=[]
if (ColumnJunctions[0]<ColumnJunctions[1])
CornerRow[0]:=RowJunctions[0]
CornerCol[0]:=ColumnJunctions[0]
CornerRow[1]:=RowJunctions[1]
CornerCol[1]:=ColumnJunctions[1]
else
CornerRow[0]:=RowJunctions[1]
CornerCol[0]:=ColumnJunctions[1]
CornerRow[1]:=RowJunctions[0]
CornerCol[1]:=ColumnJunctions[0]
endif
if (ColumnJunctions[2]<ColumnJunctions[3])
CornerRow[2]:=RowJunctions[2]
CornerCol[2]:=ColumnJunctions[2]
CornerRow[3]:=RowJunctions[3]
CornerCol[3]:=ColumnJunctions[3]
else
CornerRow[2]:=RowJunctions[3]
CornerCol[2]:=ColumnJunctions[3]
CornerRow[3]:=RowJunctions[2]
CornerCol[3]:=ColumnJunctions[2]
endif
return ()
rake (GrayImage, Regions, Elements, DetectHeight, DetectWidth, Sigma, Threshold, Transition, Select, CornerRow[0], CornerCol[0], CornerRow[1], CornerCol[1], ResultRow, ResultColumn)
pts_to_best_line (Line1, ResultRow, ResultColumn, ActiveNum, Row01, Column01, Row10, Column10)
rake (GrayImage, Regions, Elements, DetectHeight, DetectWidth, Sigma, Threshold, Transition, Select, CornerRow[2], CornerCol[2], CornerRow[3], CornerCol[3], ResultRow, ResultColumn)
pts_to_best_line (Line2, ResultRow, ResultColumn, ActiveNum, Row23, Column23, Row32, Column32)
rake (GrayImage, Regions, Elements, DetectHeight, DetectWidth, Sigma, Threshold, Transition, Select, CornerRow[0], CornerCol[0], CornerRow[2], CornerCol[2], ResultRow, ResultColumn)
pts_to_best_line (Line3, ResultRow, ResultColumn, ActiveNum, Row02, Column02, Row20, Column20)
rake (GrayImage, Regions, Elements, DetectHeight, DetectWidth, Sigma, Threshold, Transition, Select, CornerRow[1], CornerCol[1], CornerRow[3], CornerCol[3], ResultRow, ResultColumn)
pts_to_best_line (Line4, ResultRow, ResultColumn, ActiveNum, Row13, Column13, Row31, Column31)
intersection_lines (Row01, Column01, Row10, Column10, Row02, Column02, Row20, Column20, Row1, Column1, IsOverlapping)
intersection_lines (Row01, Column01, Row10, Column10, Row13, Column13, Row31, Column31, Row2, Column2, IsOverlapping)
intersection_lines (Row23, Column23, Row32, Column32, Row02, Column02, Row20, Column20, Row3, Column3, IsOverlapping)
intersection_lines (Row23, Column23, Row32, Column32, Row13, Column13, Row31, Column31, Row4, Column4, IsOverlapping)
gen_cross_contour_xld (Cross1, Row1, Column1, 96, 0)
gen_cross_contour_xld (Cross2, Row2, Column2, 96, 0)
gen_cross_contour_xld (Cross3, Row3, Column3, 96, 0)
gen_cross_contour_xld (Cross4, Row4, Column4, 96, 0)
return ()
* 计算边缘线Line1的角度Phi1
gen_region_contour_xld (Line1, Region, 'filled')
orientation_region (Region, Phi1)
if (Phi1>rad(90))
Phi1:=Phi1-rad(180)
endif
* Cross1平移
RowNew1:=Row1+TranslationX*cos(Phi1)
ColumnNew1:=Column1+TranslationX*sin(Phi1)
RowNew1:=RowNew1-Avoid1*sin(Phi1)
ColumnNew1:=ColumnNew1+Avoid1*cos(Phi1)
gen_cross_contour_xld (CrossNew1, RowNew1, ColumnNew1, 96, 0)
dev_display (CrossNew1)
* Cross2平移
RowNew2:=Row2+TranslationX*cos(Phi1)
ColumnNew2:=Column2+TranslationX*sin(Phi1)
RowNew2:=RowNew2+Avoid2*sin(Phi1)
ColumnNew2:=ColumnNew2-Avoid2*cos(Phi1)
gen_cross_contour_xld (CrossNew2, RowNew2, ColumnNew2, 96, 0)
dev_display (CrossNew2)
* 计算边缘线Line2的角度Phi2
gen_region_contour_xld (Line2, Region, 'filled')
orientation_region (Region, Phi2)
* Cross3平移
RowNew3:=Row3-TranslationX*cos(Phi1)
ColumnNew3:=Column3-TranslationX*sin(Phi1)
RowNew3:=RowNew3-Avoid1*sin(Phi1)
ColumnNew3:=ColumnNew3+Avoid1*cos(Phi1)
gen_cross_contour_xld (CrossNew3, RowNew3, ColumnNew3, 96, 0)
dev_display (CrossNew3)
* Cross4平移
RowNew4:=Row4-TranslationX*cos(Phi1)
ColumnNew4:=Column4-TranslationX*sin(Phi1)
RowNew4:=RowNew4+Avoid2*sin(Phi1)
ColumnNew4:=ColumnNew4-Avoid2*cos(Phi1)
gen_cross_contour_xld (CrossNew4, RowNew4, ColumnNew4, 96, 0)
dev_display (CrossNew4)
* 连接点胶线
gen_contour_polygon_xld (Glue1, [RowNew1,RowNew2], [ColumnNew1,ColumnNew2])
gen_contour_polygon_xld (Glue2, [RowNew3,RowNew4], [ColumnNew3,ColumnNew4])
return ()
https://download.csdn.net/download/weixin_38566632/37707775