find_shape_model

本文介绍了在图像处理中如何使用C++库进行形状匹配,通过find_shape_model函数确定模板与目标图像的关系,利用刚性仿射变换和卡尺工具创建模型,以及定位边缘并获取测量数据的过程。
摘要由CSDN通过智能技术生成

*形状匹配
    find_shape_model (ImageEmphasize, ModelID, -0.39, 0.78, 0.5, 1, 0.5, 'least_squares', [4,-2], 0.9, Row, Column, Angle, Score)
    *创建一个初始化矩阵
    hom_mat2d_identity (HomMat2D)
    *从点和角度计算刚性仿射变换,找出模板和卡尺工具的对应关系Phi
    vector_angle_to_rigid (Row3, Column3, rad(0), Row, Column, Angle, HomMat2D)
    affine_trans_point_2d (HomMat2D, [Row1,Row2],[Column1,Column2], Qx, Qy)
    affine_trans_point_2d (HomMat2D, [Row11,Row12],[Column11,Column12], Qx1, Qy1)

    *创建卡尺工具,设置参数
    create_metrology_model (MetrologyHandle1)
    create_metrology_model (MetrologyHandle2)
    add_metrology_object_generic (MetrologyHandle1, 'line', [Qx[0],Qy[0],Qx[1],Qy[1]], 20, 5, 1, 30, [], [], Index1)
    add_metrology_object_generic (MetrologyHandle2, 'line', [Qx1[0],Qy1[0],Qx1[1],Qy1[1]], 20, 5, 1, 30, [], [], Index2)
    set_metrology_object_param (MetrologyHandle1, 0, 'measure_select', 'first')
    set_metrology_object_param (MetrologyHandle2, 0, 'measure_select', 'last')
    get_metrology_object_measures (Contours1, MetrologyHandle1, 'all', 'all', Row4, Column4)
    get_metrology_object_measures (Contours2, MetrologyHandle2, 'all', 'all', Row6, Column6)
    *寻找边缘,定位卡尺坐标,此坐标是个数组
    apply_metrology_model (ImageEmphasize, MetrologyHandle1)
    apply_metrology_model (ImageEmphasize, MetrologyHandle2)
    get_metrology_object_measures (Contours3, MetrologyHandle1, 'all', 'all', Row5, Column5)
    get_metrology_object_measures (Contours4, MetrologyHandle2, 'all', 'all', Row7, Column7)

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The `find_shape_model` function in OpenCV is used for finding a shape model from a set of training images. It is part of the Shape Matching module in OpenCV, which provides tools for matching shapes based on their contour and other features. The `find_shape_model` function takes as input a set of training images, which are typically binary images with the object of interest represented as a white shape on a black background. The function then computes a shape model based on the contours of the objects in the training images. The shape model can be used for shape matching, which involves finding the best match between a given image and the shape model. This can be useful for object recognition and tracking. To use the `find_shape_model` function, you first need to create a ShapeContextDistanceExtractor object, which defines the distance metric used for shape matching. You then call the `find_shape_model` function, passing in the training images and the ShapeContextDistanceExtractor object. Here's an example of how to use the `find_shape_model` function: ``` import cv2 # Load training images img1 = cv2.imread("train1.png", cv2.IMREAD_GRAYSCALE) img2 = cv2.imread("train2.png", cv2.IMREAD_GRAYSCALE) img3 = cv2.imread("train3.png", cv2.IMREAD_GRAYSCALE) # Create ShapeContextDistanceExtractor object sc_extractor = cv2.createShapeContextDistanceExtractor() # Find shape model from training images shape_model = cv2.findShapeModel([img1, img2, img3], sc_extractor) ``` In this example, we load three training images and create a ShapeContextDistanceExtractor object. We then call the `findShapeModel` function, passing in the three training images and the ShapeContextDistanceExtractor object. The function returns a shape model, which can be used for shape matching.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值