目录
原图
检出图
示例代码
函数说明
代码
原图
检出图
示例代码
函数说明
LEDSensitivity := 0.6
LEDMinSize := 35
LEDMaxSize := 400
LEDMethod := 1
LEDType :=1
LED (Image, LEDDefectTrans, LEDSensitivity, LEDMethod, LEDType, LEDMinSize, LEDMaxSize, R, G, B, C, I, E, Va, error)
通过图像分解、色彩空间转换、区域处理、形状分析和颜色亮度计算等步骤,实现了对LED缺陷的精确识别。代码首先进行图像的粗定位和精确定位,然后根据不同的方法计算LED缺陷的颜色和亮度信息。
代码
trygen_empty_obj (LEDDefectTrans)error:=[]*decompose3 (Image, Image1, Image2, Image3)trans_from_rgb (Image1, Image2, Image3, ImageResult1, ImageResult2, ImageResult3, 'hsv')** 粗定位gray_dilation_rect (ImageResult3, ImageMax, 21, 21)threshold (ImageMax, Regions, 50, 255)connection (Regions, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 14724.8, 50000)union1 (SelectedRegions, ROI_1)dilation_rectangle1 (ROI_1, ROI, 71, 71)shape_trans (ROI, ROI, 'rectangle1')reduce_domain (ImageResult3, ROI, ImageReduced)smallest_rectangle1 (ROI, Row_1, Col_1, Row2, Column2)crop_domain (ImageReduced, ImagePart)** 定位var_threshold (ImagePart, Region, 71, 71, 0.2, 20, 'light')intensity (Region, ImagePart, Mean, Deviation)scale_image (ImagePart, ImageScaled, 1, 128-Mean)scale_image_range (ImageScaled, ImageScaled1, 128-90, 128+90)*Th := 128+127 * (1-LEDSensitivity)threshold (ImageScaled1, Regions_T, Th, 255)opening_circle (Regions_T, RegionOpening, 1.5)closing_rectangle1 (RegionOpening, RegionClosing, 4, 4)connection (RegionClosing, ConnectedRegions1)*select_shape (ConnectedRegions1, LEDDefect_T, 'area', 'and', LEDMinSize, LEDMaxSize)** 色坐标CIEtrans_from_rgb (Image1, Image2, Image3, ImageResult1, ImageResult2, ImageResult3, 'cielab')if(LEDMethod == 1)move_region (LEDDefect_T, LEDDefect, Row_1, Col_1)** 颜色RGBintensity (LEDDefect, Image1, R, Deviation)intensity (LEDDefect, Image2, G, Deviation)intensity (LEDDefect, Image3, B, Deviation)* 色坐标CIEintensity (LEDDefect, ImageResult1, C, Deviation)intensity (LEDDefect, ImageResult2, I, Deviation)intensity (LEDDefect, ImageResult3, E, Deviation)** 亮度Va := (R + G + B)/3.0else** 颜色RGBintersection (LEDDefect_T, Regions_T, RegionIntersection)move_region (RegionIntersection, LEDDefect, Row_1, Col_1)intensity (LEDDefect, Image1, R, Deviation)intensity (LEDDefect, Image2, G, Deviation)intensity (LEDDefect, Image3, B, Deviation)* 色坐标CIEintensity (LEDDefect, ImageResult1, C, Deviation)intensity (LEDDefect, ImageResult2, I, Deviation)intensity (LEDDefect, ImageResult3, E, Deviation)** 亮度Va := (R + G + B)/3.0endifif(LEDType ==1)Type := 'outer_circle'elseType := 'rectangle1'endifshape_trans (LEDDefect, LEDDefectTrans, Type)
catch (Exception)dev_get_exception_data (Exception, 'error_message', Value)gen_empty_obj (LEDDefectTrans)error := Value
endtry
return ()