13_qrCodeScanner.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. #version : 2023.12.31
  3. #language : ch
  4. from maix import camera, display, zbar, image
  5. import sys
  6. import os
  7. ScreenOrientation = False
  8. try:
  9. if os.path.exists("/etc/cameraSize.cfg"):
  10. cameraSize = True
  11. else:
  12. cameraSize = False
  13. except:
  14. cameraSize = False
  15. def getLcdRotation(cameraCapture):
  16. global cameraSize
  17. if cameraSize:
  18. return lcdRotationNew(cameraCapture)
  19. else:
  20. return lcdRotation(cameraCapture)
  21. def lcdRotationNew(inputImg):
  22. global cameraSize,ScreenOrientation
  23. imageRotationBuffer = inputImg.crop(0, 0, 320, 240)
  24. if ScreenOrientation:
  25. imgRotationAim = image.new(size = (240, 320))
  26. rotationAngle = 90
  27. GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
  28. else:
  29. imgRotationAim = image.new(size = (320, 240))
  30. GETROTATION = imageRotationBuffer
  31. GETROTATION = imgRotationAim.draw_image(GETROTATION,0,0,alpha=1)
  32. return GETROTATION
  33. def lcdRotation(inputImg):
  34. global cameraSize,ScreenOrientation
  35. imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
  36. if ScreenOrientation:
  37. imgRotationAim = image.new(size = (240, 320))
  38. rotationAngle = 180
  39. else:
  40. imgRotationAim = image.new(size = (320, 240))
  41. rotationAngle = 90
  42. GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
  43. GETROTATION = imgRotationAim.draw_image(GETROTATION,0,0,alpha=1)
  44. return GETROTATION
  45. sys.path.append('/root/CocoPi.py')
  46. image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
  47. camera.camera.config(size=(240,320))
  48. while True:
  49. canvas = getLcdRotation(camera.capture())
  50. mks = canvas.find_qrcodes()
  51. for mk in mks:
  52. #外框数据
  53. X = mk['x']
  54. Y = mk['y']
  55. W = mk['w']
  56. H = mk['h']
  57. #二维码信息
  58. string = mk['payload']
  59. #画外框
  60. canvas.draw_rectangle(X, Y, X + W, Y + H, color=(0, 0, 255), thickness = 2)
  61. #打印信息
  62. canvas.draw_string(int(X) , int(Y - 35) , str(string), scale = 1, color = (255, 0, 0), thickness = 2) #内框ID
  63. canvas.draw_image(image.open("/root/preset/img/exit_ff0000_24x24.png"),288,216,alpha=1)
  64. display.show(canvas)