halcon视觉钻石角度测量-@龙熙视觉培训

dev_update_off ()
dev_close_window ()
read_image (Image, 'diamond/diamond_01')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (2)
* 
NumImages := 5
for Index := 1 to NumImages by 1

halcon视觉钻石角度测量-@龙熙视觉培训

read_image (Image, 'diamond/diamond_' + Index$'.2')
* 
* Segment diamond region
threshold (Image, Region, 128, 255)
clip_region_rel (Region, RegionClipped, 0, 290, 0, 0)
shape_trans (RegionClipped, RegionTrans, 'convex')
dilation_rectangle1 (RegionTrans, RegionDilation, 5, 1)
erosion_rectangle1 (RegionTrans, RegionErosion, 5, 1)
difference (RegionDilation, RegionErosion, RegionDifference)
reduce_domain (Image, RegionDifference, ImageReduced)
* 
* Subpixel accurate fitting of the edges
edges_sub_pix (ImageReduced, Edges, 'canny', 3, 5, 5)
union_collinear_contours_xld (Edges, UnionContours, 100, 10, 4, rad(10), 'attr_keep')
select_contours_xld (UnionContours, SelectedContours, 'contour_length', 50, 2000, 0, 0)
fit_line_contour_xld (SelectedContours, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
* 
* Sort the edge contours and determine their intersection
tuple_sort_index (RowBegin, Indices)
RowBegin := subset(RowBegin,Indices)
RowEnd := subset(RowEnd,Indices)
ColBegin := subset(ColBegin,Indices)
ColEnd := subset(ColEnd,Indices)
Nr := subset(Nr,Indices)
Nc := subset(Nc,Indices)
Dist := subset(Dist,Indices)
gen_contour_polygon_xld (LineEdge1, [Dist[0] / Nr[0],0], [0,Dist[0] / Nc[0]])
gen_contour_polygon_xld (LineEdge2, [Dist[1] / Nr[1],Width - 1], [0,(Dist[1] - (Width - 1) * Nr[1]) / Nc[1]])

halcon视觉钻石角度测量-@龙熙视觉培训

intersection_lines (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], RowTip, ColTip, IsOverlapping)
gen_cross_contour_xld (Cross, RowTip, ColTip, 20, rad(45))
* 
* Display the results
dev_display (Image)
dev_set_color ('yellow')
dev_display (LineEdge1)
dev_display (LineEdge2)
dev_set_color ('blue')
dev_display (Cross)
if (Index != NumImages)

halcon视觉钻石角度测量-@龙熙视觉培训

    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
endif

endfor

上一篇:采用halcon开发3D视觉产品


下一篇:Halcon学习笔记(八)——OCR识别字符排列圆形或字体倾斜的处理办法