转 Halcon判断一个点是否在某个区域

本文通过实例展示了如何使用图像处理技术中的轮廓选择算法来交互式地选取图像中的特定区域,并详细解释了如何处理不同形状和交叉线条的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://blog.youkuaiyun.com/oShouQianShou/article/details/78217171

* Index of all regions containing a given pixel
*
read_image (Image, 'fabrik')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowID)
dev_set_color ('white')
dev_set_draw ('fill')
* Segment an image using regiongrowing
regiongrowing (Image, Regions, 1, 1, 3, 400)
Button := 1
dev_set_color ('red')
while (Button == 1)
    * Click with the mouse on the region to be selected
    * Quit the loop with the right mouse button
    get_mbutton (WindowID, Row, Column, Button)
    get_region_index (Regions, Row, Column, Index)
    if (Index != [])
        select_obj (Regions, ObjectSelected, Index)
    endif
endwhile


* 
* This example program shows how to use select_xld_point.
* 
* Color code:
* red - test point
* white - contours, selected
* dim gray - contours, not selected
* 
* 
* 
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
* 
* 
* 
PointRow := 100.0
PointCol := 100.0
gen_contour_polygon_xld (Contours, [50,50,150,150,50], [50,150,150,50,50])
gen_contour_polygon_xld (Contour2, [50,50,150,150,50], [200,300,300,200,200])
concat_obj (Contours, Contour2, Contours)
select_xld_point (Contours, SelectedContours, PointRow, PointCol)
gen_cross_contour_xld (Cross, PointRow, PointCol, 6, 0.785398)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_set_color ('white')
dev_display (SelectedContours)
dev_set_color ('red')
dev_display (Cross)
stop ()
* 
* 
* 
* Contours that are not closed will be closed automatically.
* Therefore, the selection for the open contours is exactly
* the same as in the previous example.
* 
PointRow := 100.0
PointCol := 100.0
gen_contour_polygon_xld (Contours, [50,50,150,150], [50,150,150,50])
gen_contour_polygon_xld (Contour2, [50,50,150,150], [200,300,300,200])
concat_obj (Contours, Contour2, Contours)
select_xld_point (Contours, SelectedContours, PointRow, PointCol)
gen_cross_contour_xld (Cross, PointRow, PointCol, 6, 0.785398)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_set_color ('white')
dev_display (SelectedContours)
dev_set_color ('red')
dev_display (Cross)
stop ()
* 
* 
* 
* Intersecting line segments may cause holes in a polygon. Note that
* line segments in real world applications will practically never intersect.
* 
PointRow := 200.0
PointCol := 200.0
gen_contour_polygon_xld (Contours, [50,50,250,250,150,150,350,350,50], [50,250,250,150,150,350,350,50,50])
select_xld_point (Contours, SelectedContours, PointRow, PointCol)
gen_cross_contour_xld (Cross, PointRow, PointCol, 6, 0.785398)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_set_color ('white')
dev_display (SelectedContours)
dev_set_color ('red')
dev_display (Cross)
stop ()
* 
* 
* 
* Points lying directly on one of the contour's line segments
* cannot be classified reliably.
* 
PointRow := 200.0
PointCol := 200.0
gen_contour_polygon_xld (Contours, [150,150,250,250,150], [100,200,200,100,100])
gen_contour_polygon_xld (Contour2, [100,100,200,200,100], [150,250,250,150,150])
concat_obj (Contours, Contour2, Contours)
gen_contour_polygon_xld (Contour3, [150,150,250,250,150], [200,300,300,200,200])
concat_obj (Contours, Contour3, Contours)
gen_contour_polygon_xld (Contour4, [200,200,300,300,200], [150,250,250,150,150])
concat_obj (Contours, Contour4, Contours)
select_xld_point (Contours, SelectedContours, PointRow, PointCol)
gen_cross_contour_xld (Cross, PointRow, PointCol, 6, 0.785398)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_set_color ('white')
dev_display (SelectedContours)
dev_set_color ('red')
dev_display (Cross)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值