halcon学習の運動追跡位置決め
3103 ワード
この例を研究すればいいのです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