码迷,mamicode.com
首页 > 其他好文 > 详细

【Halcon示例003---matching/synthetic_circle】 合成圆寻找电容

时间:2019-10-25 16:37:06      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:color   ogr   窗口   window   region   led   form   例程   clean   

 1 * ------------------------------------------------------------------------------------------------
 2 * This example program creates a synthetic model in form of a circle to
 3 * search for capacitors on a board.
 4 * 这个示例程序创建了一个圆形的合成模型来搜索板上的电容器。
 5 * ------------------------------------------------------------------------------------------------
 6 * general configuration of HDevelop  HDevelop的通常配置
 7 dev_update_window (off)
 8 * image acquisition and window size
 9 open_framegrabber (File, 1, 1, 0, 0, 0, 0, default, -1, default, -1, default, capacitors/capacitors.seq, default, -1, 1, FGHandle)
10 grab_image (ModelImage, FGHandle)
11 get_image_pointer1 (ModelImage, Pointer, Type, Width, Height)
12 dev_close_window ()
13 dev_open_window (0, 0, Width, Height, black, WindowHandle)
14 dev_set_part (0, 0, Height - 1, Width - 1)
15 dev_display (ModelImage)
16 * colors and other settings for the visualization
17 dev_set_color (cyan)
18 dev_set_draw (margin)
19 dev_set_line_width (2)
20 set_display_font (WindowHandle, 14, mono, true, false)
21 disp_continue_message (WindowHandle, black, true)
22 stop ()
23 * -------------------  start of the application  ----------------
24 * step 1: create a circle with the correct size  创建一个合适的圆
25 RadiusCircle := 43
26 SizeSynthImage := 2 * RadiusCircle + 10
27 * 创建椭圆XLD,也就是后面的模板
28 gen_ellipse_contour_xld (Circle, SizeSynthImage / 2, SizeSynthImage / 2, 0, RadiusCircle, RadiusCircle, 0, 6.28318, positive, 1.5)
29 dev_display (Circle)
30 disp_continue_message (WindowHandle, black, true)
31 * step 2: create an image and insert the XLD 创建一张图像插入XLD的圆
32 dev_open_window (0, Width + 20, SizeSynthImage, SizeSynthImage, white, WindowHandleSynthetic)
33 dev_set_part (0, 0, SizeSynthImage - 1, SizeSynthImage - 1)
34 * 重新开辟一个窗口,设置显示大小,生成空图像,将圆XLD轮廓重绘其中
35 gen_image_const (EmptyImage, byte, SizeSynthImage, SizeSynthImage)
36 paint_xld (Circle, EmptyImage, SyntheticModelImage, 128)
37 dev_display (SyntheticModelImage)
38 disp_continue_message (WindowHandle, black, true)
39 stop ()
40 * step 3: create the model  
41 inspect_shape_model (SyntheticModelImage, ShapeModelImage, ShapeModelRegion, 1, 30)
42 dev_clear_window ()
43 dev_set_color (blue)
44 dev_display (ShapeModelRegion)
45 * 【核心算子一】创建一个可变形状模板
46 create_scaled_shape_model (SyntheticModelImage, auto, 0, 0, 0.01, 0.8, 1.2, auto, none, use_polarity, 30, 10, ModelID)
47 get_shape_model_contours (ShapeModel, ModelID, 1)
48 disp_continue_message (WindowHandle, black, true)
49 stop ()
50 * step 4: find the object in other images
51 dev_set_window (WindowHandleSynthetic)
52 dev_close_window ()
53 dev_set_part (0, 0, Height - 1, Width - 1)
54 dev_set_color (yellow)
55 dev_set_line_width (2)
56 for i := 1 to 3 by 1
57     grab_image (SearchImage, FGHandle)
58     dev_display (SearchImage)
59     * 【核心算子二】寻找可变形状模板
60     find_scaled_shape_model (SearchImage, ModelID, 0, 0, 0.8, 1.2, 0.7, 0, 0.5, least_squares, 3, 0, RowCheck, ColumnCheck, AngleCheck, ScaleCheck, Score)
61     if (|Score| > 0)
62         for j := 0 to |Score| - 1 by 1
63             * 先仿射出从原点到当天模板中心的矩阵
64             vector_angle_to_rigid (0, 0, 0, RowCheck[j], ColumnCheck[j], AngleCheck[j], MovementOfObject)
65             * 比例and平移 【【【为什么RowCheck[j], ColumnCheck[j]使用了两次】】】
66             hom_mat2d_scale (MovementOfObject, ScaleCheck[j], ScaleCheck[j], RowCheck[j], ColumnCheck[j], MoveAndScaleOfObject)
67             affine_trans_contour_xld (ShapeModel, ModelAtNewPosition, MoveAndScaleOfObject)
68             dev_display (ModelAtNewPosition)
69         endfor
70     endif
71     disp_continue_message (WindowHandle, black, true)
72     stop ()
73 endfor
74 * -------------------  end of the application  -----------------
75 * clean up
76 clear_shape_model (ModelID)
77 dev_update_window (on)
78 close_framegrabber (FGHandle)

 

【Halcon示例003---matching/synthetic_circle】 合成圆寻找电容

标签:color   ogr   窗口   window   region   led   form   例程   clean   

原文地址:https://www.cnblogs.com/yangmengke2018/p/11738567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!