halcon_轮毂_孔检测rim.hdev

在这里插入图片描述

* Inspection of rim & tire
* The circular holes are extracted as well as the region containing
* the imprinted characters.
* 
* Set the display parameters and read the image
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 768, 576, 'black', WindowID)
set_display_font (WindowID, 16, 'mono', 'true', 'false')
read_image (Rim, 'rim')
dev_display (Rim)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* To find the holes, we first segment the dark regions
threshold (Rim, Dark, 0, 128)
dev_display (Rim)
dev_set_color ('green')
dev_set_draw ('fill')
dev_display (Dark)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Determine all connected components
connection (Dark, DarkRegions)
* Select regions with circular shape and an area larger than 50 pixel
select_shape (DarkRegions, Circles, ['circularity','area'], 'and', [0.85,50], [1.0,99999])
dev_display (Rim)
dev_set_colored (12)
dev_display (Circles)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* To extract a region that contains just the edges of the circles
* use dilation and erosion.
dilation_circle (Circles, ROIOuter, 8.5)
erosion_circle (Circles, ROIInner, 8.5)
difference (ROIOuter, ROIInner, ROI)
union1 (ROI, ROIEdges)
dev_display (Rim)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('green')
dev_display (ROIEdges)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Reduce the region of interest (domain) to the extracted
* regions containing the edges.
reduce_domain (Rim, ROIEdges, RimReduced)
* Extract subpixel precise edges
edges_sub_pix (RimReduced, Edges, 'canny', 4, 20, 40)
* Select only the contours with length larger than 30 pixels
select_contours_xld (Edges, RelEdges, 'length', 30, 999999, 0, 0)
dev_display (Rim)
dev_set_colored (12)
dev_display (RelEdges)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Fit an ellipse to the extracted edges
fit_ellipse_contour_xld (RelEdges, 'ftukey', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Ra, Rb, StartPhi, EndPhi, PointOrder)
display_ellipses (Rim, Row, Column, Phi, Ra, Rb, WindowID)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Next, the goal is to find the characters in the image.
* Extract small regions with low gray value.
gauss_filter (Rim, RimGauss, 11)
dyn_threshold (Rim, RimGauss, SmallAndDarkerRegion, 5, 'dark')
dev_display (Rim)
dev_set_draw ('fill')
dev_set_color ('green')
dev_display (SmallAndDarkerRegion)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Compute connected components
connection (SmallAndDarkerRegion, SmallAndDarker)
* Select all regions with an area between 40 and 400 pixels
select_shape (SmallAndDarker, CharCandidates, 'area', 'and', 40, 400)
* From these regions, select those that can be enclosed by
* a given elliptic region.
select_shape (CharCandidates, PossibleChar, ['ra','rb'], 'and', [10,5], [20,30])
dev_display (Rim)
dev_set_colored (12)
dev_display (PossibleChar)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Extract connected regions containing all the character
union1 (PossibleChar, ROI)
closing_circle (ROI, CharRegion, 17.5)
connection (CharRegion, CharBlocks)
dev_display (Rim)
dev_set_draw ('margin')
dev_display (CharBlocks)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Select the region that has an area of at least 400 pixel
select_shape (CharBlocks, CharRegion, 'area', 'and', 400, 99999)
* Transform the region into its enclosing rectangle
shape_trans (CharRegion, ROIChar, 'rectangle2')
dev_display (Rim)
dev_set_color ('green')
dev_display (ROIChar)
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_set_colored (12)
display_ellipses (Rim, Row, Column, Phi, Ra, Rb, WindowID)
* Extract all character candidate regions
* that lie in the extracted rectangle region.
intersection (CharCandidates, ROIChar, Characters)
* Show the extracted characters
dev_set_colored (12)
dev_display (Characters)
* Fit the smallest surrounding rectangle and get its orientation
smallest_rectangle2 (ROIChar, RowChar, ColumnChar, PhiChar, Length1Char, Length2Char)
* Rotate the image and regions so that the characters are parallel to the lower image border
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, rad(180) - PhiChar, RowChar, ColumnChar, HomMat2DRotate)
affine_trans_region (Characters, CharRotated, HomMat2DRotate, 'constant')
affine_trans_image (Rim, RimRotated, HomMat2DRotate, 'weighted', 'false')
dev_open_window (0, 800, 192, 144, 'black', WindowChar)
* For zooming in, extract a rectangle containing the characters
union1 (CharRotated, CharRotatedAll)
smallest_rectangle1 (CharRotatedAll, Row1, Column1, Row2, Column2)
ZoomHeight := Row2 - Row1 + 1
ZoomWidth := Column2 - Column1 + 1
ZoomFactor := min([768 / ZoomWidth,576 / ZoomHeight])
ZoomRow := (Row1 + Row2) / 2
ZoomColumn := (Column1 + Column2) / 2
dev_set_part (ZoomRow - 576 / ZoomFactor / 2, ZoomColumn - 768 / ZoomFactor / 2, ZoomRow + 576 / ZoomFactor / 2 - 1, ZoomColumn + 768 / ZoomFactor / 2 - 1)
dev_display (RimRotated)
dev_set_draw ('fill')
dev_set_colored (12)
dev_display (CharRotated)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值