设置首页收藏本站
开启左侧

ocr训练求教

[复制链接]
zhaoch 发表于 2022-11-25 14:51:08 | 显示全部楼层 |阅读模式
仿照例子做了字符训练,删除了 delete_file (TrainingFileName)这一行,把图片A的两行字符分两次训练加到文件b.trf,然后在另一个程序里使用这个b.trf识别A的所有字符,但是结果只有第二次训练的字符有效,第一次训练的字符识别错了,但是在OCR训练文件浏览器里,b.trf有两次的所有字符,为什么第一次训练的字符不能识别呢?
  1. * Step 0: Preparations
  2. FontName := 'model'
  3. *
  4. * Step 1: Segmentation
  5. dev_update_window ('off')
  6. read_image (image, 'E:/学习&测试程序/halcon练习/钢印读取-代码训练/TrainCodes_ground_truth/1669094653_image.png')
  7. get_image_size (image, Width, Height)
  8. dev_close_window ()
  9. dev_open_window (0, 0,  Width, Height, 'black', WindowID)
  10. set_display_font (WindowID, 27, 'mono', 'true', 'false')
  11. *gen_rectangle1 (ROI_0, 787.493, 126.966, 1032.9, 1266.73)
  12. gen_rectangle1 (ROI_0, 1060.25, 406.914, 1269.43, 1243.34)

  13. reduce_domain (image, ROI_0, ImageReduced)
  14. threshold (ImageReduced, RawSegmentation, 0, 95)
  15. fill_up_shape (RawSegmentation, RemovedNoise, 'area', 1, 5)
  16. opening_circle (RemovedNoise, ThickStructures, 2.5)
  17. fill_up (ThickStructures, Solid)
  18. opening_rectangle1 (Solid, Cut, 1, 7)
  19. connection (Cut, ConnectedPatterns)
  20. intersection (ConnectedPatterns, ThickStructures, NumberCandidates)
  21. select_shape (NumberCandidates, Numbers, 'area', 'and', 2000, 99999)
  22. sort_region (Numbers, FinalNumbers, 'character', 'true', 'column')
  23. dev_display (image)
  24. dev_set_color ('green')
  25. dev_set_line_width (2)
  26. dev_set_shape ('rectangle1')
  27. dev_set_draw ('margin')
  28. dev_display (FinalNumbers)
  29. *
  30. * Step2: Training file generation
  31. *TrainingNames := ['C','A','6', 'D', 'M', '2', '-', '4', '2']
  32. TrainingNames := ['5','3','9', '1', '5', '1', '4', '6']
  33. TrainingFileName := FontName + '.trf'
  34. sort_region (FinalNumbers, SortedRegions, 'character', 'true', 'row')
  35. shape_trans (SortedRegions, RegionTrans, 'rectangle1')
  36. area_center (RegionTrans, Area, Row, Column)
  37. MeanRow := mean(Row)
  38. dev_set_check ('~give_error')
  39. *delete_file (TrainingFileName)
  40. dev_set_check ('give_error')
  41. for I := 0 to |TrainingNames| - 1 by 1
  42.     select_obj (SortedRegions, CharaterRegions, I + 1)
  43.     append_ocr_trainf (CharaterRegions, ImageReduced, TrainingNames[I], TrainingFileName)
  44.     disp_message (WindowID, TrainingNames[I], 'image', MeanRow - 160, Column[I] - 6, 'yellow', 'false')
  45. endfor
  46. *
  47. * Step3: Training
  48. CharNames := uniq(sort(TrainingNames))
  49. create_ocr_class_mlp (8, 10, 'constant', 'default', CharNames, 10, 'none', 10, 42, OCRHandle)
  50. trainf_ocr_class_mlp (OCRHandle, TrainingFileName, 200, 1, 0.01, Error, ErrorLog)
  51. write_ocr_class_mlp (OCRHandle, FontName)
复制代码

捕获.PNG



奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
绝地武士 发表于 2022-11-25 15:31:32 | 显示全部楼层
微信截图_20221125153036.png
用你的OCR助手打开*.trf文件,看看训练字符与图像是否正常。建议效果不好的用深度OCR
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| zhaoch 发表于 2022-11-25 15:40:34 | 显示全部楼层
谢谢,去学深度学习了
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
老老常 发表于 2023-7-13 15:10:52 | 显示全部楼层
楼主找到问题原因了吗?
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表