halcon学习之运动跟踪定位

大家去研究这个例子就可以了:optical_flow_hydraulic_engineering.hdev,这里只是记录一下,备忘

* This example demonstrates the use of the optical flow operators.
* By calculating the optical flow between two images, the
* position, speed, and movement direction of particles are calculated.
* optical_flow_hydraulic_engineering.hdev
* 这个 例子 演示 这个 使用 属于 这个 视力的 流 操作员。 由 精明的 这个 视力的 流 之间 二 图像, 这个 位置, 速度, 和 运动 方向 属于 粒子 是 计算。
dev_update_off ()
dev_close_window ()
* 
read_image (Image1, 'hydraulic_engineering/hydraulic_engineering_01')
dev_open_window_fit_image (Image1, 0, 0, -1, -1, WindowHandle)
* 
dev_set_draw ('margin')
RCenter := -1
CCenter := -1
MeanR := 0
MeanC := 0
tanDir := 0
ArrowLength := 15
MinLength := 0.375
* 
for Index := 2 to 50 by 1
    read_image (Image2, 'hydraulic_engineering/hydraulic_engineering_' + Index$'02')
    * 计算两幅图像之间的光流
    * Calculate the optical flow between two images
    optical_flow_mg (Image1, Image2, VectorField, 'clg', 1, 1, 1000, 5, 'default_parameters', 'fast')
    vector_field_length (VectorField, LengthImage, 'squared_length')
    * 
    * Estimate the region with moving particles using the length of the vectors of the calculated vector field
    * 用计算出的向量场的向量长度估计运动粒子的区域
    min_max_gray (LengthImage, LengthImage, 0, Min, MaxLength, Range)
    if (MaxLength > MinLength)
        threshold (LengthImage, ROI, MinLength, MaxLength)
        * 使用估计ROI找到原始图像中粒子的位置
        * Find the position of particles in the original image using  an estimated ROI
        * 
        dilation_circle (ROI, RegionDilation, 3.5)
        reduce_domain (Image2, RegionDilation, ImageReduced)
        local_max_sub_pix (ImageReduced, 'facet', 1.0, 4, Row, Column)
        * 
        dev_set_color ('cyan')
        dev_set_line_width (2)
        if (|Row| > 0)
            gen_region_points (Points, Row, Column)
            connection (Points, ConnectedRegions)
            dilation_circle (ConnectedRegions, PointsDilated, 2.5)
            * 显示器发现了粒子及其运动方向
            * Display found particles and their movement directions
            count_obj (PointsDilated, NumberReg)
            dev_display (Image2)
            dev_display (PointsDilated)
            for J := 1 to NumberReg by 1
                select_obj (PointsDilated, SelectedRegions, J)
                * 估计粒子的速度
                * Estimate the speed of the particles
                reduce_domain (VectorField, SelectedRegions, ImageReducedVF)
                vector_field_to_real (ImageReducedVF, RowImage, ColumnImage)
                intensity (ColumnImage, ColumnImage, MeanC, Deviation)
                intensity (RowImage, RowImage, MeanR, Deviation)
                Length := sqrt(MeanR * MeanR + MeanC * MeanC)
                gen_arrow_contour_xld (Arrow, Row[J - 1], Column[J - 1], Row[J - 1] + MeanR / Length * ArrowLength, Column[J - 1] + MeanC / Length * ArrowLength, 5, 10)
                dev_display (Arrow)
            endfor
        endif
    endif
    copy_obj (Image2, Image1, 1, 1)
endfor

猜你喜欢

转载自blog.csdn.net/weixin_42398658/article/details/106060502
今日推荐