- dev_update_off ()
- dev_set_draw ('margin')
- *********创建模型
- read_image (Image1, '样图/样图1.png')
- rgb1_to_gray (Image1, GrayImage)
- gen_rectangle2 (ROI_0, 814.065, 821.02, rad(-137.533), 98.785, 44.7842)
- gen_rectangle2 (TMP_Region, 914.109, 415.563, rad(-18.6304), 98.5895, 34.9364)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 619.533, 122.214, rad(-77.7279), 96.6962, 43.2099)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 400.917, 931.26, rad(-74.4134), 90.4003, 44.3046)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 93.3728, 630.437, rad(-13.9223), 92.4009, 57.9936)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 210.092, 224.98, rad(-132.952), 98.7181, 61.3814)
- union2 (ROI_0, TMP_Region, ROI_0)
- reduce_domain (GrayImage, ROI_0, ImageReduced1)
- threshold (ImageReduced1, Regions, 0, 59)
- connection (Regions, ConnectedRegions1)
- select_shape (ConnectedRegions1, SelectedRegions1, 'circularity', 'and', 0.8, 1)
- select_shape (SelectedRegions1, SelectedRegions2, 'area', 'and', 150, 99999)
- union1 (SelectedRegions2, RegionUnion)
- fill_up (RegionUnion, RegionFillUp1)
- gen_contour_region_xld (RegionFillUp1, Contours, 'border')
- fit_circle_contour_xld (Contours, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
- gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
- create_shape_model_xld (ContCircle, 'auto', rad(-180), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
- find_shape_model (GrayImage, ModelID, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 4, 0.9, Row1, Column1, Angle, Score)
- dev_display_shape_matching_results2 (Contours1, ModelID, 'red', Row1, Column1, Angle, 1, 1, 0)
- gen_cross_contour_xld (Cross, Row1, Column1, 61, Angle)
- tempR:=Row1
- tempC:=Column1
- tempA:=0
- ***ROI区域
- gen_rectangle2 (ROI_0, 406.763, 121.67, rad(167.375), 30.286, 28.6463)
- gen_rectangle2 (TMP_Region, 628.147, 937.098, rad(-18.8067), 37.392, 31.8959)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 206.094, 830.455, rad(39.1622), 38.7268, 34.8598)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 810.692, 230.914, rad(-135.13), 34.8662, 31.1556)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 914.263, 636.677, rad(-75.4668), 41.4606, 24.0005)
- union2 (ROI_0, TMP_Region, ROI_0)
- gen_rectangle2 (TMP_Region, 106.406, 419.49, rad(104.533), 41.4606, 28.6706)
- union2 (ROI_0, TMP_Region, ROI_0)
- ROI:=ROI_0
- **读取视频
- open_framegrabber ('DirectFile', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', '样图/考试测试图(无损压缩).avi', 'default', -1, -1, AcqHandle)
- get_framegrabber_param (AcqHandle, 'last_frame', Value )
- set_framegrabber_param (AcqHandle, 'grab_timeout', 100)
-
- grab_image_start (AcqHandle, -1)
- for Index := 0 to Value-1 by 1
- try
- grab_image (Image, AcqHandle )
- rgb1_to_gray (Image, GrayImage)
- find_shape_model (GrayImage, ModelID, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 4, 0.9, Row1, Column1, Angle, Score)
- * dev_display_shape_matching_results2 (Contours , ModelID, 'red', Row1, Column1, Angle , 1, 1, 0)
- vector_angle_to_rigid (tempR, tempC, 0, Row1, Column1, Angle , HomMat2D)
- affine_trans_region (ROI, ROIAffineTrans, HomMat2D, 'nearest_neighbor')
- gen_empty_obj (EmptyObject)
- connection (ROIAffineTrans, ConnectedRegions3)
- count_obj (ConnectedRegions3, Number)
- for Index1 := 1 to Number by 1
- select_obj (ConnectedRegions3, ObjectSelected, Index1)
- reduce_domain (GrayImage, ObjectSelected, ImageReduced)
- binary_threshold (ImageReduced, Region1, 'max_separability', 'dark', UsedThreshold1)
- concat_obj (EmptyObject, Region1, EmptyObject)
- endfor
- closing_circle (EmptyObject, RegionClosing, 3.5)
- connection (RegionClosing, ConnectedRegions)
- closing_circle (ConnectedRegions, RegionClosing1, 53.5)
- difference ( RegionClosing1,ConnectedRegions, RegionDifference)
- connection (RegionDifference, ConnectedRegions2)
- select_shape (ConnectedRegions2, SelectedRegions, 'area', 'and', 150, 99999)
- area_center (SelectedRegions, Area, Row2, Column2)
- maxDistance:=0
- maxfirst:=0
- maxsecond:=0
- for first := 0 to |Row2|-1 by 1
- for second := 0 to |Row2|-1 by 1
- distance_pp (Row2[first], Column2[first], Row2[second], Column2[second], Distance)
- if (maxDistance<Distance)
- maxDistance:=Distance
- maxfirst:=first
- maxsecond:=second
- endif
- if (maxDistance>Distance)
- endif
- endfor
- endfor
- row:=[Row2[maxfirst],Row2[maxsecond]]
- col:=[Column2[maxfirst],Column2[maxsecond]]
- gen_contour_polygon_xld (Contour,row, col)
- dev_display (Image)
- dev_set_color ('green')
- dev_display (Contour)
- catch (Exception)
- continue
- endtry
- endfor
- close_framegrabber (AcqHandle)
复制代码 大概思路就是匹配,找缺口。具体你自己的需求改改吧
|