关键词

Halcon学习:简单目标检测(人脸识别)

此代码只是简单的实现了框选物的检测追踪。基本逻辑是基于相关性的模板匹配。如果有人脸识别库的话,可以进行人脸识别。以后会完善代码实现实时的目标追踪。

 1 *此文件夹含有多张相似的实拍图,用于检测算法的模板追踪
 2 list_files (\'C:/Users/zx80-165/Desktop/模板追踪图\', \'files\', ImageFiles)
 3 l:=|ImageFiles|
 4 read_image (Image, \'C:/Users/zx80-165/Desktop/1212.bmp\')
 5 get_image_size (Image, Width, Height)
 6 dev_open_window (0, 0, Width/2, Height/2, \'black\', WindowHandle1)
 7 dev_display (Image)
 8 disp_message (WindowHandle1, \'请创建模板并以鼠标右击结束\', \'window\', -1, -1, \'white\', \'false\')
 9 *鼠标左键框选目标模板,右键确定
10 draw_rectangle1 (WindowHandle1, Row1, Column1, Row2, Column2)
11 gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
12 area_center (Rectangle, Area, Row, Column)
13 orientation_region (Rectangle, Phi)
14 reduce_domain (Image, Rectangle, ImageReduced)
15 create_ncc_model (ImageReduced, \'auto\', -0.39, 0.79, \'auto\', \'use_polarity\', ModelID)
16 dev_set_draw (\'margin\')
17 dev_set_line_width (1)
18 *循环图片寻找相似的模板
19 for i := 1 to l-1 by 1
20     
21     read_image (Image1, ImageFiles[i])
22     find_ncc_model (Image1, ModelID, -0.39, 0.78, 0.8, 1, 0.5, \'true\', 0, Row3, Column3, Angle, Score)
23     
24     len:=|Row3|
25     if(len!=0)
26     vector_angle_to_rigid (Row, Column, Phi+rad(90), Row3, Column3, Angle, HomMat2D)
27     affine_trans_region (Rectangle, RegionAffineTrans, HomMat2D, \'nearest_neighbor\')
28     dev_display (Image1)
29     dev_display (RegionAffineTrans) 
30     else
31 32     dev_display (Image1)
33     disp_message (WindowHandle1, \'没有识别到\', \'window\', -1, -1, \'white\', \'false\')
34 35     endif
36 
37 endfor

 

 

 

 

 

本文链接:http://task.lmcjl.com/news/5430.html

展开阅读全文