读取图像
read_image (Image, 'C:/Users/gwd/Desktop/车牌5.jpg')
dev_clear_window ()
*打开新的窗口
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*获得图片的大小
get_image_size (Image, Width, Height)
*适应窗口
dev_set_part (0, 0, Height, Width)
*显示图片
ev_display (Image)
*以图片中点为旋转点进行旋转
text_line_orientation (Image, Image, 25, rad(-50), rad(50), OrientationAngle)
*旋转图片
rotate_image (Image, ImageRotate, -OrientationAngle / rad(180) * 180, 'constant')
*增强图像的对比度 7 7 1 是默认的
emphasize (ImageRotate, ImageEmphasize, 7, 7, 1)
*中值滤波 抑制小斑点或细线
median_image (ImageRotate, ImageMedian, 'circle', 5.5, 'mirrored')
*用ROI抠出数字字母识别的区域
gen_rectangle1 (ROI_0, 2420.08, 1912.42, 2717.16, 3118.68)
reduce_domain (ImageMedian, ROI_0, ImageReduced)
*车牌定位矫正
*1是先将一张3通道的彩色图分割为3个单通到的单色图
decompose3 (ImageReduced,r, g, b)
*2是将此3个单色图转换为HSV色差空间中的图
trans_from_rgb (r, g, b, h, s, v, 'hsv')
*快速二值化
binary_threshold (v, Region1, 'max_separability', 'dark', UsedThreshold1)
*形成不同的连通域
connection (Region1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, ['contlength','area','height'], 'and',[365.14,7000,30.73], [2000,50000,500])
*新能源字符库的路径【需要自己训练】
FontFile2 := 'C:/Users/gwd/Desktop/shuzi--plate.omc'
*开始排序
sort_region (SelectedRegions1, SortedRegions, 'character', 'true', 'row')
*计算字符个数Number,为显示所用
count_obj (SortedRegions, Number3)
*识别
read_ocr_class_mlp (FontFile2, OCRHandle1)
*依据OCRHandle句柄,对提取体征进行识别与学习,把结果赋值给 Class
do_ocr_multi_class_mlp (SortedRegions, ImageReduced, OCRHandle1, Class1, Confidence1)
*在图片上方显示识别的结果
disp_message (WindowHandle, Class1, 'window', 12, 12, 'black', 'true')