1. 程式人生 > 其它 >halcon多個形狀模板匹配

halcon多個形狀模板匹配

* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('GigEVision2', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', 'c42f90f5f892_Hikvision_MVCA06010GC', 0, -1, AcqHandle)
set_framegrabber_param (AcqHandle, 'DeviceUserID', '')
set_framegrabber_param (AcqHandle, 
'RegionSelector', 'Region0') set_framegrabber_param (AcqHandle, 'Width', 3072) set_framegrabber_param (AcqHandle, 'Height', 2048) set_framegrabber_param (AcqHandle, 'OffsetX', 0) set_framegrabber_param (AcqHandle, 'OffsetY', 0) set_framegrabber_param (AcqHandle, 'PixelFormat', 'YUV422_8') set_framegrabber_param (AcqHandle,
'TestPattern', 'Off') set_framegrabber_param (AcqHandle, 'AcquisitionMode', 'Continuous') set_framegrabber_param (AcqHandle, 'AcquisitionBurstFrameCount', 1) set_framegrabber_param (AcqHandle, 'AcquisitionFrameRate', 3.0) set_framegrabber_param (AcqHandle, 'AcquisitionFrameRateEnable', 1) set_framegrabber_param (AcqHandle,
'ExposureMode', 'Timed') set_framegrabber_param (AcqHandle, 'ExposureAuto', 'Continuous') set_framegrabber_param (AcqHandle, 'TriggerSelector', 'FrameBurstStart') grab_image_start (AcqHandle, -1) *使用上次的校驗資料調整影象 read_cam_par ('MV_HIK_Division2.cal', CameraParam) change_radial_distortion_cam_par ('adaptive', CameraParam, 0, CamParamOut) gen_radial_distortion_map (Map, CameraParam, CamParamOut, 'bilinear') dev_update_pc ('off') dev_update_window ('off') dev_update_var ('off') dev_close_window () dev_open_window (0, 0, 3072, 2048, 'black', WindowHandle) dev_set_draw ('margin') dev_set_line_width (3) IndexS := [] IndexE := [] gen_empty_obj (Models) * The variable ModelIDs holds the different models that are created below. ModelIDs := [] Colors := ['red','green','cyan'] for Index := 1 to 2 by 1 read_shape_model ('shape_m'+Index$'01', ModelID) get_shape_model_contours (ModelContours, ModelID, 1) count_obj (ModelContours, NumModel) count_obj (Models, NumModels) concat_obj (Models, ModelContours, Models) IndexS := [IndexS,NumModels + 1] IndexE := [IndexE,NumModels + NumModel] ModelIDs := [ModelIDs,ModelID] endfor while (true) grab_image_async (Image, AcqHandle, -1) map_image (Image, Map, ImageMapped) rgb1_to_gray (ImageMapped, GrayImage) count_seconds (S1) find_shape_models (GrayImage, ModelIDs, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', 0, 0.8, Row, Column, Angle, Score, Model) count_seconds (S2) Time := (S2 - S1) * 1000 dev_display (GrayImage) Num := |Score| for J := 0 to Num - 1 by 1 * Select the correct XLD contours from the Models object. copy_obj (Models, ModelSelected, IndexS[Model[J]], IndexE[Model[J]] - IndexS[Model[J]] + 1) * Compute the transformation from the model object to the current instance. vector_angle_to_rigid (0, 0, 0, Row[J], Column[J], Angle[J], HomMat2D) affine_trans_contour_xld (ModelSelected, ModelTrans, HomMat2D) dev_set_color (Colors[Model[J]]) dev_display (ModelTrans) *dev_disp_text (Row[J] + ',' + Column[J], 'window', Row[J], Column[J], 'black', [], []) set_tposition (WindowHandle, Row[J], Column[J]+200) write_string (WindowHandle, Row[J] + ',' + Column[J]) endfor dev_set_color ('yellow') wait_seconds (0.4) * Image Acquisition 01: Do something endwhile for J := 0 to |ModelIDs| - 1 by 1 clear_shape_model (ModelIDs[J]) endfor close_framegrabber (AcqHandle)
View Code