设为首页收藏本站
授权版本:2024_07
开启左侧

[C++] 用QT和halcon联合编程思路求助

[复制链接]
scarsss 发表于 2023-3-20 20:44:22 | 显示全部楼层 |阅读模式
领导让用QT把halcon处理的结果做个展示  halcon程序已经写好了  就是检查记录单填写是不是完整(一格三个钩至少要打一格钩,不能漏钩) 不完整界面显示错误  
目的是想在QT程序界面打开一幅图然后在一个文本控件上显示‘’完整‘或‘’不完整‘’
刚学QT 环境已经配置好了  不知道halcon导出的cpp代码要复制到哪个程序里  
1679314337222.png 1679315103784.png 1679315169470.png 1679315211578.png

以下是halcon程序 流程就是先画出几十个roi 把17个格子包含五十几个钩区域和两个签名区域截出来 然后用自己的算法检查是否漏钩或者漏签 最后输出文本结果表单是否完整

  1. read_image(Image, 'C:/Users/PC/Desktop/ocr/原图片集/元器件检查记录单.bmp')
  2. get_image_size(Image, Width, Height)
  3. dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
  4. *框选打钩区域
  5. gen_rectangle1(r0n1, 171, 329, 185, 343)
  6. gen_rectangle1(r0n2, 171, 404, 185, 418)

  7. gen_rectangle1 (r1n1, 244, 703, 258, 717)
  8. gen_rectangle1 (r1n2, 244, 787, 258, 801)
  9. gen_rectangle1 (r1n3, 244, 913, 258, 927)
  10. …………(省略剩下的几十个方框)

  11. reduce_domain(Image, r0n1, ImageReduced1)
  12. reduce_domain(Image, r0n2, ImageReduced2)
  13. reduce_domain(Image, r1n1, ImageReduced3)
  14. reduce_domain(Image, r1n2, ImageReduced4)
  15. reduce_domain(Image, r1n3, ImageReduced5)
  16. reduce_domain(Image, r2n1, ImageReduced6)
  17. reduce_domain(Image, r2n2, ImageReduced7)
  18. reduce_domain(Image, r2n3, ImageReduced8)
  19. ……(同上)


  20. *这些自定义函数是检查每一格2或3或4或6个钩中内至少要一个打钩,输出结果是result,只有‘ok'或'error'两种情况
  21. FindTickFrom2 (ImageReduced1, ImageReduced2, Regions, Row, Column, Radius, tuple0, Min, result0)

  22. FindTickFrom3 (ImageReduced3, ImageReduced4, ImageReduced5, Regions, Row, Column, Radius, tuple1, Min, result1)
  23. FindTickFrom3 (ImageReduced6, ImageReduced7, ImageReduced8, Regions, Row, Column, Radius, tuple2, Min, result2)
  24. FindTickFrom3 (ImageReduced9, ImageReduced10, ImageReduced11, Regions, Row, Column, Radius, tuple3, Min, result3)
  25. FindTickFrom3 (ImageReduced12, ImageReduced13, ImageReduced14, Regions, Row, Column, Radius, tuple4, Min, result4)
  26. FindTickFrom3(ImageReduced15, ImageReduced16, ImageReduced17, Regions, Row, Column, Radius, tuple5, Min, result5)
  27. FindTickFrom3 (ImageReduced18, ImageReduced19, ImageReduced20, Regions, Row, Column, Radius, tuple6, Min, result6)
  28. FindTickFrom3 (ImageReduced21, ImageReduced22, ImageReduced23, Regions, Row, Column, Radius, tuple7, Min, result7)
  29. FindTickFrom6 (ImageReduced24, ImageReduced25, ImageReduced26, ImageReduced27, ImageReduced28, ImageReduced29, Regions, Row, Column, Radius, tuple8, Min, result8)
  30. FindTickFrom4 (ImageReduced30, ImageReduced31, ImageReduced32, ImageReduced33, Regions, tuple9, result9)
  31. FindTickFrom3 (ImageReduced34, ImageReduced35, ImageReduced36, Regions, Row, Column, Radius, tuple10, Min, result10)
  32. FindTickFrom3 (ImageReduced37, ImageReduced38, ImageReduced39, Regions, Row, Column, Radius, tuple11, Min, result11)
  33. FindTickFrom3 (ImageReduced40, ImageReduced41, ImageReduced42, Regions, Row, Column, Radius, tuple12, Min, result12)
  34. FindTickFrom3 (ImageReduced43, ImageReduced44, ImageReduced45, Regions, Row, Column, Radius, tuple13, Min, result13)
  35. FindTickfrom4 (ImageReduced46, ImageReduced47, ImageReduced48, ImageReduced49, Regions, Row, Column, Radius, tuple14, Min, result14)
  36. FindTickFrom3 (ImageReduced50, ImageReduced51, ImageReduced52, Regions, Row, Column, Radius, tuple15, Min, result15)
  37. FindTickFrom2 (ImageReduced53, ImageReduced54, Regions, Row, Column, Radius, tuple16, Min, result16)
  38. FindTickFrom2 (ImageReduced55, ImageReduced56, Regions, Row, Column, Radius, tuple17, Min, result17)
  39. dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
  40. *把17格的检查结果汇总  这17个字符串不是ok就是error
  41. TickCheckResult:=[result0,result1,result2,result3,result4,result5,result6,result7,result8,result9,result10,result11,result12,result13,result14,result15,result16,result17]
  42. counterror:=[]
  43. for i:=0 to 17 by 1
  44.     if (TickCheckResult[i]='error')
  45.     num:=i+1
  46.     disp_message(WindowHandle, '第'+num+'个区域内没有打钩!', 'window', i*4, 10, 'red', 'true')
  47.     counterror:=[counterror,'缺少打钩']
  48.     stop()
  49.     endif      
  50. endfor

  51. *检查签名区域
  52. gen_rectangle1 (s1, 1260, 430, 1320, 660)
  53. gen_rectangle1 (s2,1260,810,1320,1040)
  54. *自定义检查签名函数,输出结果是result,只有‘ok'或'error'两种情况
  55. CheckSignatureResult (Image, s1, ImageReduceds1, Regions1, RegionDilation1, result18)
  56. CheckSignatureResult (Image, s2, ImageReduceds2, Regions2, RegionDilation2, result19)

  57. CheckSignatureResult:=[result18,result19]
  58. *如果漏签就报错
  59. for j:=0 to 1 by 1
  60.    if (CheckSignatureResult[j]='error')
  61.      disp_message(WindowHandle, '缺少签名!', 'window', 30, 30, 'red', 'true')
  62.   counterror:=[counterror,'缺少签名']
  63.   endif
  64. endfor
  65. tuple_length(counterror, Length)
  66. if(Length >0)
  67.     disp_message(WindowHandle, '表单不完整', 'window', 0, 0, 'red', 'true')
  68. endif
复制代码







奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| scarsss 发表于 2023-3-20 20:47:00 | 显示全部楼层
导出的c++代码在QT里打开后好长  不知道是不是全复制到  mainwindow .cpp 程序里  还是只复制action函数里面的代码?
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Criss 发表于 2023-3-30 14:08:45 | 显示全部楼层
scarsss 发表于 2023-3-20 20:47
导出的c++代码在QT里打开后好长  不知道是不是全复制到  mainwindow .cpp 程序里  还是只复制action函数里 ...

action里面是你写的代码。需要根据实际情况拷贝到对应方法下面,可能会在不同的方法下面。
同时action外面的也要注意,引用的外部方法的实现是需要单独拷贝过去的,不然会找不到定义,出现无法解析的外部符号。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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