当前位置:网站首页>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
边栏推荐
- 出门带着小溪
- Nat. Comm. | supercomputing +ai: providing navigation for natural product biosynthesis route planning
- Lambda快速入门
- Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe
- Flink CDC + Hudi 海量数据入湖在顺丰的实践
- C language string and pointer - learning 25
- [case] building a universal data lake for Fuguo fund based on star ring technology data cloud platform TDC
- In the field of enabling finance, the transformation of state secrets makes security compliance more solid
- 王希廷博士:从知识图谱和自然语言生成的角度认识可解释推荐
- Current situation investigation and demand forecast report of global and Chinese phenolic resin market, 2022 Edition
猜你喜欢

be based on. NETCORE development blog project starblog - (11) access statistics

flowable 工作流

一、Flutter 入门学习写一简单客户端

Low code platform design exploration, how to better empower developers

Some suggestions on writing code to reproduce the paper!

How can functional tests be quickly advanced in one month? It is not a problem to clarify these two steps
![[case] building a universal data lake for Fuguo fund based on star ring technology data cloud platform TDC](/img/62/e53a83f04a5eab7ae4db47e8d4f3e5.jpg)
[case] building a universal data lake for Fuguo fund based on star ring technology data cloud platform TDC

Recurrent+Transformer 视频恢复领域的‘德艺双馨’

Tencent programmer roast: 1kW real estate +1kw stock +300w cash, ready to retire at the age of 35

ROS2之OpenCV基础代码对比foxy~galactic~humble
随机推荐
Lambda intermediate operation sorted
Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
Building circuits on glass
How to strengthen the prevention and control of major safety risks for chemical and dangerous goods enterprises in flood season
Codemirror 2 - highlight only (no editor) - codemirror 2 - highlight only (no editor)
[answer] in the business sequence diagram of XX shopping mall, is it drawn as a business executor (bank) or a business entity (banking system)
How to guarantee industrial control safety: system reinforcement
Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe
Adult education online training website open source
2022 edition of global and Chinese sodium hydrosulfide market in-depth investigation and prospect Trend Forecast Report
Zhongchuang patents | China has 18000 necessary patents for 5g standards, respects intellectual property rights and jointly builds a strong intellectual property country
Global and Chinese chromatographic silica gel resin industry research and investment direction forecast report 2022 Edition
Lambda intermediate operation filter
Scope and category of C language variables - learning 20
Crawler small case 04 - use beautiful soup to batch obtain pictures
Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
Creating a flutter high performance rich text editor - rendering
Intel trimbert: tailor Bert for trade-offs
Bgfx multithreaded rendering
Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security