当前位置:网站首页>Halcon clolor_ pieces. Hedv: classifier_ Color recognition

Halcon clolor_ pieces. Hedv: classifier_ Color recognition

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

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image, 'E:/03 CV( ancient )/Halcon/ Code / Sugar bean /train.jpg')
Regions:=[' yellow ',' red ',' green ',' orange ',' background ']
gen_empty_obj (Classes)# Create an empty object , To save training samples 
for i := 1 to |Regions| by 1
    dev_display (Image)
    dev_display (Classes)
    disp_message (WindowHandle, ' Please select the specified area :', 'window', 12, 12, 'black', 'true')
    draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2) # Rectangular frame , You can also draw a frame of any shape 
    gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
    concat_obj (Rectangle, Classes, Classes)
endfor

# Create classifier , Add data , Training data 
*union1 (Classes, RegionUnion)* Not used here union1
create_class_mlp (3,7, 5, 'softmax', 'normalization', 3, 42, MLPHandle)# If it is a three channel color image , The first parameter can be set 3, The third parameter is the number of output parameters, that is Class Number of colors included , Remove the background color . The second parameter is the third parameter 2 About times .
add_samples_image_class_mlp (Image, Classes, MLPHandle)# Put the training sample Class  Add to network 

disp_message (WindowHandle, 'Training...', 'window', 100, 12, 'black', 'false')
train_class_mlp (MLPHandle, 400, 0.5, 0.01, Error, ErrorLog)

*test distinguish 
for i := 1 to 3 by 1
    read_image (Image1, 'E:/03 CV( ancient )/Halcon/ Code / Sugar bean /test0'+i)
    classify_image_class_mlp (Image1, ClassRegions, MLPHandle, 0.5) # Classify and recognize objects 
    # Show 
    for Index := 1 to 5 by 1
        dev_clear_window ()
        copy_obj (ClassRegions, ObjectsSelected, Index, 1)# Choose one 
        dev_display (Image1)
        dev_display (ObjectsSelected)
        disp_message (WindowHandle, Regions[5-Index], 'window', 10, 10, 'black', 'true')
    endfor
endfor

原网站

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