13_qrCodeScanner.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. #version : 2023.04.04
  3. #language : ch
  4. from maix import camera, display, zbar, image
  5. import sys
  6. sys.path.append('/root/CocoPi.py')
  7. ScreenOrientation = False
  8. image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
  9. camera.camera.config(size=(240,320))
  10. def lcdRotation(inputImg,rotationAngle):
  11. from maix import image
  12. imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
  13. if ScreenOrientation:
  14. imgRotationAim = image.new(size = (240, 320))
  15. else:
  16. imgRotationAim = image.new(size = (320, 240))
  17. return imgRotationAim.draw_image(imageRotationBuffer.rotate(rotationAngle, adjust=1),0,0,alpha=1)
  18. if ScreenOrientation:
  19. CAMERAROTATE = +180
  20. else:
  21. CAMERAROTATE = +90
  22. while True:
  23. canvas = lcdRotation(camera.capture(),CAMERAROTATE)
  24. mks = canvas.find_qrcodes()
  25. for mk in mks:
  26. #外框数据
  27. X = mk['x']
  28. Y = mk['y']
  29. W = mk['w']
  30. H = mk['h']
  31. #二维码信息
  32. string = mk['payload']
  33. #画外框
  34. canvas.draw_rectangle(X, Y, X + W, Y + H, color=(0, 0, 255), thickness = 2)
  35. #打印信息
  36. canvas.draw_string(int(X) , int(Y - 35) , str(string), scale = 1, color = (255, 0, 0), thickness = 2) #内框ID
  37. canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
  38. display.show(canvas)