QQ登录

只需一步,快速开始

halcon projective_trans_contour_xld函数介绍

[ 复制链接 ]
projective_trans_contour_xld(Contours : ContoursProjTrans : HomMat2D : )
projective_trans_contour_xld用齐次变换矩阵HomMat2D 对Contours 进行投影变换,
结果保存于ContoursProjTrans 。

使用的坐标系与affine_trans_pixel中的坐标系相同。
这意味着实际上应用的不是HomMat2D,而是修改后的版本。
因此,应用projective_trans_contour_xld对应于下面的变换链,
它应用于轮廓的每一点(Row_i,Col_i)(输入和输出像素作为齐次向量):
2019-05-19_232901.jpg


因此,当基于从轮廓派生的坐标(例如area_center_xld之类的操作符)创建投影转换时,
可能会得到意想不到的结果。
例如,如果使用这个操作符计算旋转对称的XLD轮廓的重心,
然后使用hom_mat2d_rotate将轮廓绕该点旋转,
得到的轮廓将不会位于原来的轮廓上。
在这种情况下,您可以在projective_trans_contour_xld中使用HomMat2D之前,
执行下面代码来补偿:
hom_mat2d_translate(HomMat2D, 0.5, 0.5, HomMat2DTmp)
  hom_mat2d_translate_local(HomMat2DTmp, -0.5, -0.5, HomMat2DAdapted)
  projective_trans_contour_xld(Contours, ContoursAffineTrans, HomMat2DAdapted)

下面为halcon自带例程,可以再次F5查看效果
read_image (Image, 'olympic_stadium')
get_image_size (Image, Width, Height)
decompose3 (Image, ImageR, ImageG, ImageB)
trans_from_rgb (ImageR, ImageG, ImageB, ImageH, ImageS, ImageV, 'hsv')
threshold (ImageH, GreenRegion, 60, 90)
connection (GreenRegion, ConnectedRegions)
select_shape_std (ConnectedRegions, RectangleRegions, 'rectangle2', 80)
select_shape_std (RectangleRegions, Field, 'max_area', 90)
shape_trans (Field, FieldConvex, 'convex')
boundary (FieldConvex, FieldBorder, 'inner')
dilation_rectangle1 (FieldBorder, FieldDilation, 7, 7)
reduce_domain (Image, FieldDilation, ImageReduced)
edges_color_sub_pix (ImageReduced, Edges, 'canny', 1.5, 20, 40)
select_shape_xld (Edges, SelectedEdges, 'contlength', 'and', 15, 500)
segment_contours_xld (SelectedEdges, ContoursSplit, 'lines', 5, 4, 2)
regress_contours_xld (ContoursSplit, RegressContours, 'no', 1)
select_contours_xld (RegressContours, SelectedContours, 'curvature', 0, 0.5, 0, 0)
select_shape_xld (SelectedContours, SelectedEdges, 'contlength', 'and', 15, 500)
union_collinear_contours_xld (SelectedEdges, UnionContours, 30, 1, 4, 0.1, 'attr_forget')


select_shape_xld (UnionContours, HorizontalEdges, 'phi', 'and', rad(-20), rad(20))
select_shape_xld (UnionContours, VerticalEdges, ['phi','phi'], 'or', [rad(-90),rad(60)], [rad(-60),rad(90)])
fit_line_contour_xld (HorizontalEdges, 'tukey', -1, 0, 10, 2, RowBegHor, ColBegHor, RowEndHor, ColEndHor, NrHor, NcHor, DistHor)
IndexHor := sort_index(RowBegHor)
fit_line_contour_xld (VerticalEdges, 'tukey', -1, 0, 10, 2, RowBegVer, ColBegVer, RowEndVer, ColEndVer, NrVer, NcVer, DistVer)
IndexVer := sort_index(ColBegVer)


intersection_lines (RowBegHor[IndexHor[0]], ColBegHor[IndexHor[0]], RowEndHor[IndexHor[0]], ColEndHor[IndexHor[0]], RowBegVer[IndexVer[0]], ColBegVer[IndexVer[0]], RowEndVer[IndexVer[0]], ColEndVer[IndexVer[0]], RowUL, ColUL, IsOverlapping)
intersection_lines (RowBegHor[IndexHor[0]], ColBegHor[IndexHor[0]], RowEndHor[IndexHor[0]], ColEndHor[IndexHor[0]], RowBegVer[IndexVer[1]], ColBegVer[IndexVer[1]], RowEndVer[IndexVer[1]], ColEndVer[IndexVer[1]], RowUR, ColUR, IsOverlapping)
intersection_lines (RowBegHor[IndexHor[1]], ColBegHor[IndexHor[1]], RowEndHor[IndexHor[1]], ColEndHor[IndexHor[1]], RowBegVer[IndexVer[0]], ColBegVer[IndexVer[0]], RowEndVer[IndexVer[0]], ColEndVer[IndexVer[0]], RowLL, ColLL, IsOverlapping)
intersection_lines (RowBegHor[IndexHor[1]], ColBegHor[IndexHor[1]], RowEndHor[IndexHor[1]], ColEndHor[IndexHor[1]], RowBegVer[IndexVer[1]], ColBegVer[IndexVer[1]], RowEndVer[IndexVer[1]], ColEndVer[IndexVer[1]], RowLR, ColLR, IsOverlapping)
gen_contour_polygon_xld (FieldBorder, [RowUL,RowUR,RowLR,RowLL,RowUL], [ColUL,ColUR,ColLR,ColLL,ColUL])
dev_display (Image)
dev_display (FieldBorder)
stop ()
*上面代码为球场边缘轮廓提取,以下为projective_trans_contour_xld调用部分
vector_to_proj_hom_mat2d ([RowUL,RowUR,RowLR,RowLL] + 0.5, [ColUL,ColUR,ColLR,ColLL] + 0.5, [160,160,340,340] + 0.5, [250,550,550,250] + 0.5, 'normalized_dlt', [], [], [], [], [], [], HomMat2D, Covariance)
projective_trans_image_size (Image, TransImage, HomMat2D, 'bilinear', 800, 500, 'false')
projective_trans_contour_xld (FieldBorder, FieldBorderTrans, HomMat2D)
dev_set_window_extents (-1, -1, 800, 500)
dev_display (TransImage)
dev_display (FieldBorderTrans)


  

halcon从自学到接项目视频教程,另外再赠送全网最全资源  

  

欢迎围观我录制的一套halcon自学视频教程(进入)




回复

使用道具 举报

快速回复 返回列表 客服中心 搜索