当前位置:网站首页>Halcon color recognition_ fuses. hdev:classify fuses by color

Halcon color recognition_ fuses. hdev:classify fuses by color

2022-07-05 08:40:00 Aii parson

* Refresh the window     Turn off 
dev_update_window('off')
* name     Give the selected thing a name (a It's a variable , You can use it , As long as it's in English )
a:=[' Orange ',' Red ',' Blue ',' yellow ',' green ']
* classification     There are several kinds of things to choose (fusetypes Used to cycle , You can name it as you like , As long as it's in English )
fusetypes:=[1,2,3,4,5]
* Name the gray value range      Something has a certain scope ( Such as : Orange 10-30, Red 0-10.. It can also be size “ area ”, shape )
hueranges:=[10,30,0,10,125,162,30,64,96,128]
* close window (   Closing the window first is to ensure that the window is not closed under special circumstances )
dev_close_window ()
* open windows 
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)


* Read images  
read_image (Image, ' Color recognition picture .png')
* Display images 
dev_display (Image)
* Settings window     Used to display content ( second 、 The three parameters are where to display )
set_tposition (WindowHandle, 10, 512)
* Display the content in the set window     The second parameter is what you want 
write_string (WindowHandle, ' Color recognition ')


* Split into RGB Images  
decompose3 (Image, Red, Green, Blue)
*RGB The image turns into HSV Images  
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
* Graying ( Yes S The component image is grayed , Choose a few things you want )
threshold (Saturation, Regions, 60, 261)# Can also be directly in Hue Choose from the top 
* Regional segmentation     stay H Components are divided into grayed S Area of component ( If we H Component processing ...) 
reduce_domain (Hue, Regions, ImageReduced)

* Establish a cycle    fuse It's a variable. , It can be letters or English 
* stay fusetypes Class from 0 Start to deal with , Deal with one at a time 
for fuse:=0 to |fusetypes| -1 by 1

    * Gray the segmented area ( Be careful : The grayed value is determined by the third ( minimum value )、 Four parameters ( Maximum ) decision )
    *hueranges The scope has been divided at the beginning 
   *  Such as :fuse=0,   Then the value is   10-30,fuse=1   Then the value is    0-10
    threshold (ImageReduced, Regions1,hueranges[fuse*2],hueranges[fuse*2+1])
 * Disconnect connected domain    
connection (Regions1, ConnectedRegions)
* Filling and flushing 
fill_up (ConnectedRegions, RegionFillUp)
* feature selection    ( Be careful : You cannot choose features related to location , This program is selected by using area characteristics ,
                   * The choice of area cannot be too small or too large , Otherwise, you won't be able to choose )
 select_shape (RegionFillUp, SelectedRegions, 'area', 'and', 3998.14, 10000)
 * Find the area 、 Central coordinates ( Used to display the location of the content to be displayed )
area_center (SelectedRegions, fuseArea, Row, Column)
* Set the color of the content font to be displayed 
dev_set_color ('red')
* loop     This loop is used to display the name of the obtained thing , |fuseArea| To express a 
for i:=0   to |fuseArea| -1 by 1
    * Settings window     Used to display content ( second 、 The three parameters are where to display , The position of this instruction is variable (i It's a variable ))
    set_tposition (WindowHandle, Row[i], Column[i]-15)
    * Display the content in the set window     The second parameter is what you want ( The content of this article is based on a Named after    Variable 
    *fuse To show ,fusea The value of is determined by the previous cycle , What was dealt with in the previous loop? There will be corresponding values )
    write_string (WindowHandle, a[fuse])
* End of cycle (   Be careful :   Loops must be in pairs , Otherwise you'll make a mistake   )    
endfor

* Display the operation result of this program 
 * Settings window     Used to display content    
set_tposition (WindowHandle, 16*[fuse+1], 16)
 * Display the content in the set window    use ‘’ What is displayed directly    The second parameter is what you want  
 *                                                ( Show : name     Number 》 Must use | | Encircle )
write_string (WindowHandle, a[fuse]+'  '+|fuseArea|)
disp_message (3600, ' Pay attention to WeChat public number ( Robots are equipped with vision   ind400)', 'window', 300, 120, 'black', 'true')

endfor
* Refresh the window     open ( Refresh the window after program execution , Or you'll make a mistake  )
dev_update_window('on')

原网站

版权声明
本文为[Aii parson]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140541151156.html