在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
《zw版·Halcon-delphi系列原创教程》酸奶自动分类脚本(机器学习、人工智能) Halcon强大的图像处理能力,令人往往会忽视其内核,是更加彪悍的机器学习、人工智能。 分类,聚类分析,是机器学习、人工智能的核心算法之一,也是个典型的应用。 Halcon内置的聚类分析、机器学习模块,就有:knn邻近算法、向量机SVM、GMM高斯混合模型(Gaussian Mixture Model,或者混合高斯模型,也可以简写为MOG(Mixture of Gaussian)、MLP(多层神经网络)等等。 目前国内、海外机器学习、人工智能方面的学者,没有几位重视这块。
Halcon因为面向一线生产线,所以很多机器学习、人工智能,都是黑箱式的,无需编程,直接调用,例如内置的ocr模块,可以识别99%的标准工业字符:超市、海关、流水线、零配件
Halcon自带demo脚本:matching_multi_channel_yogurl.hdev 选这个脚本,其中一个原因,是因为前几天,有人在论坛询问,如何对企业生产线的产品(零食好像?)进行自动分类。
1 * This example demonstrates shape based matching 2 * with multi channel images 3 * 4 * Init display 5 dev_update_off () 6 Mode := 'multi channel' 7 ModelColor := 'green' 8 CircleColor := 'white' 9 Names := ['Pear Apple Hazelnut','Cherry Currant','Strawberry'] 10 read_image (Image, 'color/yogurt_model_01') 11 get_image_size (Image, Width, Height) 12 dev_close_window () 13 dev_open_window (0, 0, Width, Height, 'black', WindowHandle) 14 set_display_font (WindowHandle, 14, 'mono', 'true', 'false') 15 * 16 * Part 1: create shape models 17 ModelIDs := [] 18 for Index := 1 to 3 by 1 19 read_image (Image, 'color/yogurt_model_' + Index$'02') 20 dev_display (Image) 21 * 22 * Create ROI automatically 23 access_channel (Image, Channel1, 1) 24 fast_threshold (Channel1, Region, 75, 255, 20) 25 fill_up (Region, RegionFillUp) 26 opening_circle (RegionFillUp, RegionOpening, 170.5) 27 gen_contour_region_xld (RegionOpening, Contours, 'border') 28 fit_circle_contour_xld (Contours, 'geotukey', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder) 29 gen_circle (Circle, Row, Column, Radius / 2) 30 reduce_domain (Image, Circle, ImageReduced) 31 * 32 * Create model 33 create_shape_model (ImageReduced, 6, rad(0), rad(360), 'auto', 'auto', 'ignore_color_polarity', [35,50,15], 11, ModelID) 34 ModelIDs := [ModelIDs,ModelID] 35 * 36 * Display model 37 dev_set_color (CircleColor) 38 dev_set_draw ('margin') 39 dev_set_line_width (5) 40 dev_display (Circle) 41 get_shape_model_contours (Model1Contours, ModelID, 1) 42 dev_set_color (ModelColor) 43 dev_set_line_width (2) 44 dev_display_shape_matching_results (ModelIDs, ModelColor, Row, Column, 0.0, 1, 1, ModelID) 45 disp_message (WindowHandle, 'Create shape model ' + Names[Index - 1], 'window', 12, 12, 'black', 'true') 46 disp_message (WindowHandle, 'Press \'Run\' to continue', 'window', 450, 12, 'black', 'true') 47 stop () 48 endfor 49 * Main loop: Find yogurt 50 for Index := 1 to 10 by 1 51 read_image (Image, 'color/yogurt_' + Index$'02') 52 * Preprocessing: Reduce search domain to speed up matching 53 access_channel (Image, Channel1, 1) 54 fast_threshold (Channel1, Region, 50, 255, 20) 55 fill_up (Region, RegionFillUp) 56 erosion_rectangle1 (RegionFillUp, RegionErosion, 210, 210) 57 reduce_domain (Image, RegionErosion, ImageReduced) 58 * Find yogurt 59 find_shape_models (ImageReduced, ModelIDs, rad(0), rad(360), 0.80, 1, 0.5, 'least_squares', 0, 0.95, Row, Column, Angle, Score, Model) 60 * 61 * Display results 62 dev_display (Image) 63 gen_circle (Circle, Row, Column, Radius / 2) 64 dev_set_color (CircleColor) 65 dev_set_line_width (5) 66 dev_display (Circle) 67 get_shape_model_contours (ModelContours, Model, 1) 68 dev_set_color (ModelColor) 69 dev_set_line_width (2) 70 dev_display_shape_matching_results (ModelIDs, ModelColor, Row, Column, Angle, 1, 1, Model) 71 disp_message (WindowHandle, Names[find(ModelIDs,Model)] + ' found', 'window', 12, 12, 'black', 'true') 72 disp_message (WindowHandle, 'Score ' + Score, 'window', 50, 12, 'black', 'true') 73 if (Index < 10) 74 disp_continue_message (WindowHandle, 'black', 'true') 75 stop () 76 endif 77 endfor 78 * 79 * Cleanup memory 80 clear_shape_model (ModelIDs[0]) 81 clear_shape_model (ModelIDs[1]) 82 clear_shape_model (ModelIDs[2])
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论