当前位置:网站首页>Defect detection, introduction to Halcon case.
Defect detection, introduction to Halcon case.
2022-06-12 01:01:00 【Children who love French fries】
defect detection ,halcon Introduction to cases .
Common defects :
1. Convex concave structure ( Contains small burrs ).
2. Internal stain , Uneven surface , defects , Holes , be damaged , burns , Youze .
3. Scratches .
processing method :
- Polishing treatment
Scratches . Low angle ring light , Turn the background white , The scratches darken .
Bump , Use a low angle ring light , Darken the background , The convex point is whitened .
Pit , Use vertical light ( Can be annular ), Light up the background , The background is darkened .
【 You can use a light bar to fight 】
Surface Fonts ( Bulge ), Use tile mounted curved light plate , Drive into the side at an angle , The font can be highlighted .
2. Algorithm to deal with
Blob analysis + feature detection
Blob analysis + features + Difference
frequency + Space
Photometric stereometry
Feature training ( classifier , Deep learning )
measurement + fitting
3. halcon Defect cases .
Case a : routine :blob analysis ——check_hazelnut_wafers.hdev( Check the cookies )
sketch :inspect quality of hazelnut wafers( Check the quality of biscuits )
// The surface is damaged in a large area
Blob+ feature detection
- Take images
- Binary segmentation binary_threshold
binary_threshold (Image, Foreground, ‘smooth_histo’, ‘light’, UsedThreshold)
// Image Read in the picture ,
// Foreground Output area
//'smooth_histo’ Segmentation algorithm
// 'light’ Extract the bright part
// UsedThreshold Output parameters - Morphological open operation opening_circle( Remove a small number of pixels )
- feature extraction area_holes ( Find the hole )
- Directly calculate the rectangularity rectangularity
- Use interpretation if. Judge the value of holes or rectangularity
Case 2 : routine :blob analysis ——fin.hdev( Finned object )
sketch :inspect a contour for fins.( Check the outline of the heat sink )
//
Blob analysis + Difference + feature detection - Take images
- Binary segmentation binary_threshold
binary_threshold (Image, Background, ‘max_separability’, ‘light’, UsedThreshold)
// 'max_separability’ Maximum separation method - Closed operation closing_circle( Fill area )
- Difference operation difference
- Morphological open operation
- Find the area
- Judge whether it is a defect
Case three : routine :blob analysis ——inspect_bottle_mouth.hdev( Check the bottle mouth )
sketch :check bottle mouths for defects( Check whether the bottle mouth is defective )
Blob+ feature detection
Case four : routine :blob analysis ——novelty_detection_dyn_threshold.hdev
sketch :inspect a web using dyn_threshold( Use dyn_ Threshold check network )
// Used to stabilize the light , The environment is simple
Code :
dev_update_window (‘off’)
read_image (Image, ‘plastic_mesh/plastic_mesh_01’)
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
set_display_font (WindowHandle, 18, ‘mono’, ‘true’, ‘false’)
dev_set_draw (‘margin’)
dev_set_line_width (3)
for J := 1 to 14 by 1
read_image (Image, ‘plastic_mesh/plastic_mesh_’ + J$‘02’)
mean_image (Image, ImageMean, 49, 49)
// Mean filtering , Pull the grayscale value to smooth
dyn_threshold (Image, ImageMean, RegionDynThresh, 5, ‘dark’)
// Use local threshold to segment the image ,
// Image: The input image .ImageMean: Enter the comparison image .RegionDynThresh: Output image .5,: threshold .‘dark’: Select the dark part
// Establish a detection system for image gray value .5: Is the threshold . Calculate the input image and the comparison image , You can select the bright and dark parts of the input image .‘dark’: To get the dark part .‘light’: Select the bright part for .Lightdark: Select the original part for
// It is often used after mean filtering
connection (RegionDynThresh, ConnectedRegions)
// feature extraction
select_shape (ConnectedRegions, ErrorRegions, ‘area’, ‘and’, 500, 99999)
count_obj (ErrorRegions, NumErrors)
dev_display (Image)
dev_set_color (‘red’)
dev_display (ErrorRegions)
if (NumErrors > 0)
disp_message (WindowHandle, ‘Mesh not OK’, ‘window’, 24, 12, ‘black’, ‘true’)
else
disp_message (WindowHandle, ‘Mesh OK’, ‘window’, 24, 12, ‘black’, ‘true’)
endif
if (J < 14)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endif
endfor
Case 5 : routine :blob analysis ——novelty_detection_dyn_threshold.hdev
sketch :inspect a web using dyn_threshold( Use dyn_ Threshold check network )
// be used for pcb Detection of small line breaks
Code
*blob+ Difference + features
read_image (Image, ‘pcb’)
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
dev_display (Image)
// Grayscale morphology
// Grayscale open operation , corrosion , Dark pixels increase
gray_opening_shape (Image, ImageOpening, 7, 7, ‘octagon’)
// Gray closed operation , inflation , Bright pixels increase
gray_closing_shape (Image, ImageClosing, 7, 7, ‘octagon’)
// Difference
dyn_threshold (ImageOpening, ImageClosing, RegionDynThresh, 75, ‘not_equal’)
dev_display (Image)
dev_set_color (‘red’)
dev_set_draw (‘margin’)
dev_display (RegionDynThresh)
Case 6 : routine :blob analysis ——check_blister.hdev( Test a tablet )
// Test a tablet for defects .
Code
- location ,blob analysis + Feature recognition
dev_close_window ()
dev_update_off ()
read_image (ImageOrig, ‘blister/blister_reference’)
dev_open_window_fit_image (ImageOrig, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
dev_set_draw (‘margin’)
dev_set_line_width (3)
access_channel (ImageOrig, Image1, 1)
// Equivalent to the gray conversion effect
// A channel that accesses a multi-channel image . That's right RGB3 One channel of the channel is extracted , Equivalent to converting to grayscale image
threshold (Image1, Region, 90, 255)
// Two valued
shape_trans (Region, Blister, ‘convex’)
orientation_region (Blister, Phi)
// Detection angle
area_center (Blister, Area1, Row, Column)
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
affine_trans_image (ImageOrig, Image2, HomMat2D, ‘constant’, ‘false’)
// Affine variation
gen_empty_obj (Chambers)
// Count
for I := 0 to 4 by 1
Row := 88 + I * 70
for J := 0 to 2 by 1
Column := 163 + J * 150
gen_rectangle2 (Rectangle, Row, Column, 0, 64, 30)
concat_obj (Chambers, Rectangle, Chambers)
// Display, draw image and count the single area of the tablet
// Put the extracted image of a single tablet on Chambers Array , Facilitate subsequent de intersection
endfor
endfor
affine_trans_region (Blister, Blister, HomMat2D, ‘nearest_neighbor’)
// Affine change the region
difference (Blister, Chambers, Pattern)
// Find the difference . Calculate the difference between the affine transformation region and the tablet region , Used to extract tablet area
union1 (Chambers, ChambersUnion)
// Form a connected domain
orientation_region (Blister, PhiRef)
// Calculate the angle of the positive area
PhiRef := rad(180) + PhiRef
area_center (Blister, Area2, RowRef, ColumnRef)
// Find the coordinates
// End of positioning
// defect detection ( Find the intersection between the tablet and the original area at the standard position )
Count := 6
for Index := 1 to Count by 1
read_image (Image, ‘blister/blister_’ + Index$‘02’)
threshold (Image, Region, 90, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 5000, 9999999)
shape_trans (SelectedRegions, RegionTrans, ‘convex’)
orientation_region (RegionTrans, Phi)
area_center (RegionTrans, Area3, Row, Column)
vector_angle_to_rigid (Row, Column, Phi, RowRef, ColumnRef, PhiRef, HomMat2D)
affine_trans_image (Image, ImageAffineTrans, HomMat2D, ‘constant’, ‘false’)
// Find the area where the image is located , It is convenient to crop the image
// Tablet segmentation
reduce_domain (ImageAffineTrans, ChambersUnion, ImageReduced)
// Crop the tablet area of the image
decompose3 (ImageReduced, ImageR, ImageG, ImageB)
//hsv conversion
var_threshold (ImageB, Region, 7, 7, 0.2, 2, ‘dark’)
// Yes v To binarize
connection (Region, ConnectedRegions0)
// To break off
closing_rectangle1 (ConnectedRegions0, ConnectedRegions, 3, 3)
// Closed operation
fill_up (ConnectedRegions, RegionFillUp)
// fill
select_shape (RegionFillUp, SelectedRegions, ‘area’, ‘and’, 1000, 99999)
opening_circle (SelectedRegions, RegionOpening, 4.5)
connection (RegionOpening, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 1000, 99999)
shape_trans (SelectedRegions, Pills, ‘convex’)
*
* Classify segmentation results and display statistics
count_obj (Chambers, Number)
gen_empty_obj (WrongPill)
gen_empty_obj (MissingPill)
// establish 2 An empty count array
for I := 1 to Number by 1
select_obj (Chambers, Chamber, I)
intersection (Chamber, Pills, Pill)
// Take the intersection of the tablet and the area where the tablet is located
area_center (Pill, Area, Row1, Column1)
if (Area > 0)
min_max_gray (Pill, ImageB, 0, Min, Max, Range)
// Find the minimum and maximum gray value
if (Area < 3800 or Min < 60)
concat_obj (WrongPill, Pill, WrongPill)
endif
else
concat_obj (MissingPill, Chamber, MissingPill)
endif
endfor
*
dev_clear_window ()
dev_display (ImageAffineTrans)
dev_set_color (‘forest green’)
count_obj (Pills, NumberP)
count_obj (WrongPill, NumberWP)
count_obj (MissingPill, NumberMP)
dev_display (Pills)
if (NumberMP > 0 or NumberWP > 0)
disp_message (WindowHandle, ‘Not OK’, ‘window’, 12, 12 + 600, ‘red’, ‘true’)
else
disp_message (WindowHandle, ‘OK’, ‘window’, 12, 12 + 600, ‘forest green’, ‘true’)
endif
*
Message := '# Correct pills: ’ + (NumberP - NumberWP)
Message[1] := '# Wrong pills : ’ + NumberWP
Message[2] := '# Missing pills: ’ + NumberMP
*
Colors := gen_tuple_const(3,‘black’)
if (NumberWP > 0)
Colors[1] := ‘red’
endif
if (NumberMP > 0)
Colors[2] := ‘red’
endif
disp_message (WindowHandle, Message, ‘window’, 12, 12, Colors, ‘true’)
dev_set_color (‘red’)
dev_display (WrongPill)
dev_display (MissingPill)
if (Index < Count)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
endif
stop ()
endfor
Case seven : routine : Template matching ( Based on relevance )——measure_fill_level.hdev( Check the liquid level )
// Check whether the bottled liquid is too much or too little .
Code :
// Positioning first , Then set a fixed height , Continue to measure the height
// Take images
dev_close_window ()
dev_update_off ()
read_image (Image, ‘ampoules/ampoules_01’)
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_line_width (2)
dev_set_draw (‘margin’)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
// Template matching
// Cutout
gen_rectangle1 (Rectangle, 230, 280, 317, 330)
reduce_domain (Image, Rectangle, ImageModel)
create_shape_model (ImageModel, ‘auto’, 0, 0, ‘auto’, ‘auto’, ‘use_polarity’, ‘auto’, ‘auto’, ModelID)
// Create a template
gen_measure_rectangle2 (0, 0, rad(90), 75, 20, Width, Height, ‘bilinear’, MeasureHandle)
// Form a measurement rectangle
Tolerance := 15
NumImages := 8
for Index := 1 to NumImages by 1
read_image (Image, ‘ampoules/ampoules_’ + Index$’.2d’)
ColumnEdges := []
FillLevelHeight := []
// Define an array
find_shape_model (Image, ModelID, 0, 0, 0.7, 0, 0.1, ‘least_squares’, 0, 0.9, Row, Column, Angle, Score)
// Find the template coordinates
MeanRow := mean(Row)
// Take the mean value of the row coordinates
RefLevel := MeanRow - 160
* Display tolerance area
dev_display (Image)
dev_set_line_width (1)
dev_set_color (‘white’)
gen_rectangle2 (AcceptLevel, RefLevel, mean(Column), 0, 30 + (max(Column) - min(Column)) / 2, Tolerance)
// Form reference rectangle
dev_display (AcceptLevel)
dev_set_line_width (2)
Errors := 0
for Idx := 0 to |Score| - 1 by 1
translate_measure (MeasureHandle, MeanRow - 135, Column[Idx])
// Measure rectangle parallel
measure_pos (Image, MeasureHandle, 2, 7, ‘all’, ‘first’, RowEdge, ColumnEdge, Amplitude, Distance)
// Find the measuring edge
// Continue to subtract the edge of the liquid level from the reference line, which is greater than or less than a certain value to detect whether there is an error .
FillLevelHeight := [FillLevelHeight,RowEdge]
ColumnEdges := [ColumnEdges,ColumnEdge]
gen_cross_contour_xld (Cross, RowEdge, ColumnEdge, 15, 0)
// formation x Mark
gen_rectangle2 (FillLevel, RowEdge, ColumnEdge, 0, 28, 20)
// Form a rectangle
if (abs(FillLevelHeight[Idx] - RefLevel) >= Tolerance)
gen_rectangle2 (ChamberSingle, MeanRow - 133, Column[Idx], 0, 35, 90)
gen_cross_contour_xld (Cross, FillLevelHeight[Idx], ColumnEdges[Idx], 15, 0)
gen_rectangle2 (FillLevel, FillLevelHeight[Idx], ColumnEdges[Idx], 0, 28, 20)
// Draw the wrong area
Errors := Errors + 1
dev_set_color (‘red’)
dev_display (ChamberSingle)
disp_message (WindowHandle, ‘NG’, ‘image’, FillLevelHeight[Idx] - 50, ColumnEdges[Idx] - 10, ‘red’, ‘false’)
else
disp_message (WindowHandle, ‘OK’, ‘image’, FillLevelHeight[Idx] - 50, ColumnEdges[Idx] - 10, ‘green’, ‘false’)
dev_set_color (‘green’)
endif
dev_display (FillLevel)
dev_display (Cross)
endfor
if (Errors > 0)
disp_message (WindowHandle, Errors + ’ BAD’, ‘window’, 10, 12, ‘red’, ‘true’)
else
disp_message (WindowHandle, ‘All OK’, ‘window’, 10, 12, ‘forest green’, ‘true’)
endif
if (Index < NumImages)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endif
endfor
边栏推荐
- 2022 edition of global and Chinese on silicon liquid crystal market supply and demand research and prospect Trend Forecast Report
- [roe] (2) roe agreement
- Data visualization big screen - big screen cloud minimalist user manual
- Adult education online training website open source
- Breadth first search depth first search dynamic programming leetcode topic: delivering information
- C language string and pointer - learning 25
- DDD exaggeration, Eric Evans made a bad start
- Lambda termination operation foreach
- [answer] is ubiquitous language a pseudo innovation?
- Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]
猜你喜欢

网狐游戏服务器-房间配置向导-组件属性与基本配置赋值

Before applying data warehouse ODBC, you need to understand these problems first

Streaming data warehouse storage: requirements and architecture

100 deep learning cases | day 41: speech recognition - pytorch implementation

What are the advantages of Tiktok applet
![Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]](/img/78/f36cdc53b94dc7da576d114a3eb2a6.png)
Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]

Inventory: more than 20 typical safety incidents occurred in February, with a loss of nearly $400million

Learn to crawl steadily 07 - detailed explanation of how to use XPath

Sharing of Manta network parallel chain solutions by Hufu Research Institute

How can functional tests be quickly advanced in one month? It is not a problem to clarify these two steps
随机推荐
[answer] is ubiquitous language a pseudo innovation?
Xiaomu's interesting PWN
Adult education online training website open source
Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
2022 edition of global and Chinese on silicon liquid crystal market supply and demand research and prospect Trend Forecast Report
在玻璃上构建电路
Why are the values of ordereddict not equal- Why are the values of an OrderedDict not equal?
Henan Zhongchuang - from cloud to edge, how edge computing enables data centers
DDD exaggeration, Eric Evans made a bad start
Comparison of OpenCV basic codes of ros2 foxy~galactic~humble
C language structure - learning 27
C language string and pointer - learning 25
2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]表示点i到点j的距离或者权重, 而在二部
System.CommandLine选项Option
Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe
LabVIEW Arduino electronic weighing system (project Part-1)
C language pointer and array - learning 23
出门带着小溪
Devops landing practice drip and pit stepping records - (1)
Big sword