ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

first_example_shape_matching.hdev解析

first_example_shape_matching.hdev解析 * ---------------------------------------- * This example shows the matching workflow * ---------------------------------------- * * ------------------- Preparation ---------------- * General configuration of HDevelop. * 关闭图形显示 dev_update_window (off) * * Image acquisition and window size. * 读图 read_image (Image, board/board_01) * 获取图像宽高 get_image_size (Image, Width, Height) * 获取活动窗口句柄 dev_get_window (WindowHandle) * 句柄不存在 if (WindowHandle -1) * 新建窗口返回句柄 dev_open_window (0, 0, Width / 2, Height / 2, black, WindowHandle) else * 缩放窗口到合适尺寸 dev_resize_window_fit_size (0, 0, Width / 2, Height / 2, -1, -1) endif * 设置图形窗口显示部分 dev_set_part (0, 0, Height - 1, Width - 1) * 显示图像 dev_display (Image) * Colors and other settings for the visualization. * 设置前景色 dev_set_color (yellow) * 设置画笔形状 dev_set_draw (margin) * 设置线宽 dev_set_line_width (2) * 设置字体 set_display_font (WindowHandle, 14, mono, true, false) disp_continue_message (WindowHandle, black, true) stop () * * ------------------- Application Start ---------------- * * step 1: Specify the model object. * 生成矩形ROI gen_rectangle1 (ROI, 450, 470, 580, 755) * 显示ROI dev_display (ROI) * 裁剪ROI区域 reduce_domain (Image, ROI, ModelImage) disp_continue_message (WindowHandle, black, true) stop () * * step 2: Create the model. * 检测形状模板 inspect_shape_model (ModelImage, ShapeModelImages, ShapeModelRegions, 8, 30) * 清除图形窗口 dev_clear_window () * 设置前景色 dev_set_color (blue) * 显示形状模板区域 dev_display (ShapeModelRegions) * 获取形状模板区域的面积和中心 area_center (ShapeModelRegions, AreaModelRegions, RowModelRegions, ColumnModelRegions) * Possible way to determine the model levels. * 形状模板区域计数 count_obj (ShapeModelRegions, HeightPyramid) * 区域面积大于15则更新NumLevels for i : 1 to HeightPyramid by 1 if (AreaModelRegions[i - 1] 15) NumLevels : i endif endfor * 创建形状模板 create_generic_shape_model (ModelID) * 设置形状模板参数num_levels set_generic_shape_model_param (ModelID, num_levels, NumLevels) * 训练形状模板 train_generic_shape_model (ModelImage, ModelID) disp_continue_message (WindowHandle, black, true) stop () * * step 3: Find the object in other images. dev_set_color (yellow) * 循环读图 for i : 2 to 9 by 1 read_image (SearchImage, board/board_ i$02) * 查找形状模板 find_generic_shape_model (SearchImage, ModelID, MatchResultID, NumMatchResult) * 匹配结果数量大于0 if (NumMatchResult 0) dev_display (SearchImage) * 获取形状模板结果对象 get_generic_shape_model_result_object (Objects, MatchResultID, all, contours) dev_display (Objects) endif if (i ! 9) disp_continue_message (WindowHandle, black, true) endif stop () endfor * * ------------------- Application End ----------------- * dev_update_window (on)
返回列表