halcon进行深度学习OCR识别
【代码】halcon进行深度学习OCR识别。
·
halcon进行深度学习OCR识别
apply_deep_ocr (Image, DeepOcrHandle, 'auto', DeepOcrResult)

* 读取图片
read_image (Image, 'D:/ocr.png')
* 获取显示窗口的句柄
dev_get_window (WindowHandle)
* 设置文字的字体和大小
set_font (WindowHandle, 'Courier New-Bold-' + round(26))
* 创建OCR识别句柄
create_deep_ocr ('mode', 'auto', DeepOcrHandle)
* 创建CPU/GPU设备句柄
query_available_dl_devices ('runtime', 'cpu', DLDeviceHandle)
* 设置OCR使用的设备
set_deep_ocr_param (DeepOcrHandle, 'device', DLDeviceHandle)
* 记录开始时间
count_seconds(StartTime)
* 执行OCR
apply_deep_ocr (Image, DeepOcrHandle, 'auto', DeepOcrResult)
* 记录结束时间
count_seconds(EndTime)
* 计算耗时
Duration := EndTime - StartTime
* 绘制文字
write_string (WindowHandle, '耗时'+Duration+'s')
* 获取结果
get_dict_tuple (DeepOcrResult, 'words', WordsRes)
* 获取文字区域的行坐标
get_dict_tuple (WordsRes, 'row', Rows)
* 获取文字区域的列坐标
get_dict_tuple (WordsRes, 'col', Cols)
* 获取文字区域的倾斜角度
get_dict_tuple (WordsRes, 'phi', Phis)
* 获取文字区域的矩形长边
get_dict_tuple (WordsRes, 'length1', Length1s)
* 获取文字区域的矩形短边
get_dict_tuple (WordsRes, 'length2', Length2s)
* 获取识别文字结果
get_dict_tuple (WordsRes, 'word', Words)
* 设置绘制模式为画轮廓
dev_set_draw('margin')
* 设置画线的宽度
dev_set_line_width (2)
for Index := 0 to |Rows|-1 by 1
* 绘制带方向的矩形
disp_rectangle2(WindowHandle, Rows[Index], Cols[Index], Phis[Index], Length1s[Index], Length2s[Index])
* 设置文字的坐标
set_tposition(WindowHandle, Rows[Index], Cols[Index])
* 绘制文字
write_string (WindowHandle, Words[Index])
endfor

更多推荐


所有评论(0)