Halcon - extend region where it intersects with another region

天大地大妈咪最大 提交于 2020-12-13 03:12:37

问题


Left image is my starting situation: red is a region, and black is a XLD rectangle.

The right is what I would like to achive. I would need that wherever the Region touches the Rectangle, the region is stretched out by X pixel.. my approach would be to draw a rectangular region with Width "X" and then unite it "union2()" but I have a difficult time to figure out the Y coordinates of the rectangles. Better yet, I can find the intersections, but I do not know how to find out if it is the "beginning" or the "end" of the intersection, so if it is the top or the bottom of the rectangle.. I was thinking that the first is alway the beginning and then they alternate, but in reality it happens that the intersection returns two values at the same pixel..


回答1:


Here a demo code

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)

* Creation of a Region
gen_circle (Circle1, 150, 200, 100.5)
gen_circle (Circle2, 250, 150, 50.5)
gen_circle (Circle3, 350, 200, 100.5)
union2 (Circle1, Circle2, RegionUnion1)
union2 (Circle3, RegionUnion1, Region)

* Creation of a xld
gen_rectangle2_contour_xld (Rectangle_xld, 250, 210, 0, 100.5, 205.5)

* Convert xld to region
gen_region_contour_xld (Rectangle_xld, Rectangle_region, 'margin')

* intersection
intersection (Region, Rectangle_region, RegionIntersection)

* stretch RegionIntersection
Stretch := 30
area_center (RegionIntersection, AreaRegionIntersection, RowRegionIntersection, ColumnRegionIntersection)

hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_scale (HomMat2DIdentity, 1, -Stretch, RowRegionIntersection, ColumnRegionIntersection, HomMat2DScale)
affine_trans_region (RegionIntersection, RegionIntersectionStretched, HomMat2DScale, 'nearest_neighbor')

union2 (Region, RegionIntersectionStretched, FinalRegion)

The input

The output



来源:https://stackoverflow.com/questions/64355720/halcon-extend-region-where-it-intersects-with-another-region

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!