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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章