当前位置:网站首页>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')
边栏推荐
猜你喜欢
STM32 single chip microcomputer - external interrupt
实例006:斐波那契数列
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Lori remote control commissioning record
Guess riddles (6)
How apaas is applied in different organizational structures
Example 009: pause output for one second
Shell script
Sword finger offer 09 Implementing queues with two stacks
猜谜语啦(11)
随机推荐
Five design details of linear regulator
Basic number theory - fast power
Guess riddles (6)
Typescript hands-on tutorial, easy to understand
Sword finger offer 06 Print linked list from end to end
Stm32--- systick timer
Illustration of eight classic pointer written test questions
关于线性稳压器的五个设计细节
[牛客网刷题 Day4] JZ35 复杂链表的复制
Xrosstools tool installation for X-Series
剑指 Offer 05. 替换空格
Program error record 1:valueerror: invalid literal for int() with base 10: '2.3‘
leetcode - 445. 两数相加 II
Shift operation of complement
My university
Bit operation related operations
实例007:copy 将一个列表的数据复制到另一个列表中。
319. Bulb switch
Classification of plastic surgery: short in long long long
696. 计数二进制子串