jerrywky 2019-10-08 18:52 采纳率: 0%
浏览 4497
已结题

HALCON 算子inspect_shape_model 和create_shape_model相关参数的关系是怎样的?

HALCON自带例程有个印刷检测的例程print_check,其中用到了两个算子:

1、inspect_shape_model (ImageReduced, ModelImages, ModelRegions,1,20)

2、create_shape_model (ImageReduced, 5, rad(-10), rad(20), 'auto', 'none', 'use_polarity', 20, 10, ShapeModelID)

有几个问题不明白,请高手帮忙指点一下。

1、inspect_shape_model 算子的用途是啥?金字塔层数和对比度两个参数,应该如何设定比较合理,或者,应该依据什么来设定?

2、在例程中,inspect_shape_model 金字塔层数和对比度的值分别为1和20,在后面的create_shape_model算子中,金字塔层数为5,并没有和inspect_shape_model 中的层数保持一致。既然参数值可以不一致,为何还要调用inspect_shape_model 算子?

3、inspect_shape_model 算子中,关于参数Contrast的定义是“Threshold or hysteresis thresholds for the contrast of the object in the image and optionally minimum size of the object parts.”,应该如何正确理解这个定义,特别是“optionally minimum size of the object parts”具体是什么意思。

4、算子create_shape_model(Template : : NumLevels, AngleStart, AngleExtent, AngleStep, Optimization, Metric, Contrast, MinContrast : ModelID) 和find_shape_model(Image : : ModelID, AngleStart, AngleExtent, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels, Greediness : Row, Column, Angle, Score) 中 参数 AngleStart, AngleExtent对应关系是怎样的?如果要检测的图像的方向0°-360°都有可能,那么该如何设置这两个算子的 AngleStart, AngleExtent?

望高手帮忙指点一下。非常感谢!!!

以下是HALCON例程代码

dev_update_off ()
read_image (Image, 'pen/pen-01')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_color ('red')
dev_display (Image)
* Note: the shape model will be constructed from a ROI that is computed
* automatically based on a simple image segmentation.
threshold (Image, Region, 100, 255)
fill_up (Region, RegionFillUp)
difference (RegionFillUp, Region, RegionDifference)
shape_trans (RegionDifference, RegionTrans, 'convex')
dilation_circle (RegionTrans, RegionDilation, 8.5)
reduce_domain (Image, RegionDilation, ImageReduced)
inspect_shape_model (ImageReduced, ModelImages, ModelRegions, 1, 20)
gen_contours_skeleton_xld (ModelRegions, Model, 1, 'filter')
area_center (RegionDilation, Area, RowRef, ColumnRef)
create_shape_model (ImageReduced, 5, rad(-10), rad(20), 'auto', 'none', 'use_polarity', 20, 10, ShapeModelID)
create_variation_model (Width, Height, 'byte', 'standard', VariationModelID)
for I := 1 to 15 by 1
    read_image (Image, 'pen/pen-' + I$'02d')
    find_shape_model (Image, ShapeModelID, rad(-10), rad(20), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
    if (|Score| == 1)
        vector_angle_to_rigid (Row, Column, Angle, RowRef, ColumnRef, 0, HomMat2D)
        affine_trans_image (Image, ImageTrans, HomMat2D, 'constant', 'false')
        train_variation_model (ImageTrans, VariationModelID)
        dev_display (ImageTrans)
        dev_display (Model)
    endif
endfor
get_variation_model (MeanImage, VarImage, VariationModelID)
prepare_variation_model (VariationModelID, 20, 3)
* We can now free the training data to save some memory.
clear_train_data_variation_model (VariationModelID)
* Note: the checking of the print will be restricted to the region of the clip.
* Sometimes the print is also in an incorrect position of the clip.  This will lead
* to erroneous regions at the top or bottom border of the clip and hence can
* be detected easily.
erosion_rectangle1 (RegionFillUp, RegionROI, 1, 15)
dev_display (MeanImage)
set_tposition (WindowHandle, 20, 20)
dev_set_color ('green')
write_string (WindowHandle, 'Reference image')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_display (VarImage)
set_tposition (WindowHandle, 20, 20)
dev_set_color ('green')
write_string (WindowHandle, 'Variation image')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_draw ('margin')
NumImages := 30
for I := 1 to 30 by 1
    read_image (Image, 'pen/pen-' + I$'02d')
    find_shape_model (Image, ShapeModelID, rad(-10), rad(20), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
    if (|Score| == 1)
        vector_angle_to_rigid (Row, Column, Angle, RowRef, ColumnRef, 0, HomMat2D)
        affine_trans_image (Image, ImageTrans, HomMat2D, 'constant', 'false')
        reduce_domain (ImageTrans, RegionROI, ImageReduced)
        compare_variation_model (ImageReduced, RegionDiff, VariationModelID)
        connection (RegionDiff, ConnectedRegions)
        select_shape (ConnectedRegions, RegionsError, 'area', 'and', 20, 1000000)
        count_obj (RegionsError, NumError)
        dev_clear_window ()
        dev_display (ImageTrans)
        dev_set_color ('red')
        dev_display (RegionsError)
        set_tposition (WindowHandle, 20, 20)
        if (NumError == 0)
            dev_set_color ('green')
            write_string (WindowHandle, 'Clip OK')
        else
            dev_set_color ('red')
            write_string (WindowHandle, 'Clip not OK')
        endif
    endif
    if (I < NumImages)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
clear_shape_model (ShapeModelID)
clear_variation_model (VariationModelID)

望高手能够帮忙解惑,非常感谢!

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-10-08 22:11
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献