find_shape_model

    find_shape_model (Image, ModelID, rad(-90), rad(180), 0.7, 1, 0.5, 'least_squares', 0, 0.5,modelRow1, modelColumn1, modelAngle1, Score1)
    if (|modelAngle1|>0)
        vector_angle_to_rigid (0, 0, 0, modelRow1, modelColumn1, modelAngle1, HomMat2D)
        affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)
             dev_set_draw ('margin')
        vector_angle_to_rigid (modelRow0, modelColumn0, modelAngle0, modelRow1, modelColumn1, modelAngle1, HomMat2D1)
        affine_trans_region (Rectangle, RegionAffineTrans0, HomMat2D1, 'nearest_neighbor')
    endif

    read_image (Image, ImageFiles[Index])
    find_shape_model (Image, ModelID, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, RowCur, ColumnCur, AngleCur, Score)
    *得到现在图片与模板图 矩阵变化
    vector_angle_to_rigid (RowModel, ColumnModel, AngleModel, RowCur, ColumnCur, AngleCur, HomMat2D)
*     hom_mat2d_identity (HomMat2DIdentity)
*     hom_mat2d_rotate (HomMat2DIdentity, AngleCur, 0, 0, HomMat2DRotate)
*     hom_mat2d_translate (HomMat2DRotate, RowCur, ColumnCur, HomMat2DTranslate)
    *将模板轮廓 根据矩阵变化 贴合现在图片显示
     affine_trans_contour_xld (Edges, ContoursAffineTrans, HomMat2D)

*读取待旋转图片
read_image(Image, '待旋转')
*获取大小
get_image_size (Image, Width, Height)
*关闭当前活动图形窗口
dev_close_window ()
*建立和原图一样大小的窗口
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
*选择区域填充模式
dev_set_draw ('fill')
*获取RGB三幅图
decompose3 (Image, R, G, B)
*对B进行阈值化(这个根据情况选择)
threshold (B, Regions, 87, 255)
*连接区域
connection (Regions, ConnectedRegions)
*根据像素面积大小选择区域(注意:这里不灵活,图片一变就不适应了。)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 200000, 210000)
*填满区域
fill_up (SelectedRegions, RegionFillUp)
*获取区域Phi(这里要理解Phi是什么,自己去理解吧!!)
orientation_region (RegionFillUp, Phi)
*根据Phi旋转原图
rotate_image (Image, ImageRotate, 3.1415-Phi, 'constant')
*清理活动窗口
dev_clear_window()
*显示最终旋转后的图片
dev_display (ImageRotate)

read_image(Image2,'C:/ Users / Pictures / 2.png')
*匹配01:模型初始化生成代码的BEGIN
set_system('border_shape_models','false')
*匹配01:获取模型图像
*匹配01:假设图像在
*匹配中可用01:变量最后显示在图形窗口中
copy_obj(Image2,Image,1,1)
*匹配01:从基本区域构建ROI
gen_rectangle1(ModelRegion,363.354,445.481,465.233,537.484)
*匹配01:减少模型模板
reduce_domain (Image,ModelRegion,TemplateImage)
*匹配01:创建形状模型
create_shape_model(TemplateImage,3,rad(0),rad(360),rad(2.5886),['none','no_pregeneration'],'use_polarity',[16,22,4],10,ModelId)
*匹配01 :获取模型轮廓以便稍后将其转换为图像
get_shape_model_contours(ModelContours,ModelId,1)
*匹配01:生成代码的END用于模型初始化
*匹配01:模型应用生成代码的BEGIN
*匹配01:以下操作是通常移动到
*匹配01:处理获取图像的循环
*匹配01:找到模型

*图像采集01:图像采集生成的代码01
list_files('C:/ Users / Pictures',['files',' follow_links'],ImageFiles)
tuple_regexp_select(ImageFiles,['\\。(tif | tiff | gif | bmp | jpg | jpeg | jp2 | png | pcx | pgm | ppm | pbm | xwd | ima | hobj),'ignore_case'],ImageFiles)
索引:= 0到| ImageFiles | -  1 by 1
    read_image(Image,ImageFiles [Index])
    *图像采集01:做一些事情
    find_shape_model(Image,ModelId,rad(0),rad(360),0.7,0,0.5,'least_squares',[3,1 ],1,ModelRow,ModelColumn,ModelAngle,ModelScore)
*匹配01:将模型轮廓转换

为MatchingObjIdx 的检测位置:= 0到| ModelScore | -  1 by 1
    hom_mat2d_identity(HomMat)
    hom_mat2d_rotate(HomMat,ModelAngle [MatchingObjIdx],0,0,HomMat)
    hom_mat2d_translate(HomMat,ModelRow [MatchingObjIdx],ModelColumn [MatchingObjIdx],HomMat)
    affine_trans_contour_xld(ModelContours,TransContours,HomMat)
    disp_message(3600,deg(ModelAngle),'window',20,20,'black','true')
    dev_display(TransContours)
endfor
endfor


*匹配01:完成时清除模型
clear_shape_model(ModelId )

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值