03_colorDetection.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. #version : 2023.04.06
  3. #language : ch
  4. from maix import display
  5. from maix import image
  6. from maix import camera
  7. camera.camera.config(size=(240,320))
  8. ScreenOrientation = False
  9. def lcdRotation(inputImg,rotationAngle):
  10. from maix import image
  11. imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
  12. if ScreenOrientation:
  13. imgRotationAim = image.new(size = (240, 320))
  14. else:
  15. imgRotationAim = image.new(size = (320, 240))
  16. return imgRotationAim.draw_image(imageRotationBuffer.rotate(rotationAngle, adjust=1),0,0,alpha=1)
  17. if ScreenOrientation:
  18. CAMERAROTATE = +180
  19. else:
  20. CAMERAROTATE = +90
  21. image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
  22. while True:
  23. canvas = lcdRotation(camera.capture(),CAMERAROTATE)
  24. RGB = canvas.get_blob_color((154, 114, 10, 10), 0, 0)
  25. canvas.draw_rectangle(154,114, 164,124, color=(255,0,0), thickness=1)
  26. canvas.draw_rectangle(0,0, 319,20, color=((int(RGB[0])),(int(RGB[1])),(int(RGB[2]))), thickness=-1)
  27. canvas.draw_string(120,0, (''.join([str(x) for x in ["(", int(RGB[0]), ",", int(RGB[1]), ",", int(RGB[2]), ")"]])), scale = 1, color = ((255 - int(RGB[0])),(255 - int(RGB[1])),(255 - int(RGB[2]))), thickness = 1)
  28. if ScreenOrientation:
  29. canvasVER = canvas.crop(0,0,240,320)
  30. canvasVER = canvasVER.rotate(-90, adjust=1)
  31. display.show(canvasVER)
  32. else:
  33. display.show(canvas)