Always-on computer music
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
807B

  1. import cv2
  2. import math
  3. import itertools as it
  4. DENSITY = 5
  5. RED = [0, 0, 255]
  6. def draw_rectangles(frame):
  7. """ Draw some rectangles on top of the image """
  8. height, width, d = frame.shape
  9. n = DENSITY
  10. m = math.ceil(n * (height / width))
  11. dx = width / n
  12. dy = height / m
  13. for x, y in it.product(range(n), range(n)):
  14. sp = (int(x * dx), int(y * dy))
  15. ep = (int(x * dx + dx), int(y * dy + dy))
  16. frame = cv2.rectangle(frame, sp, ep, (255, 0, 0))
  17. return frame
  18. if __name__ == '__main__':
  19. camera = cv2.VideoCapture(0)
  20. while True:
  21. ret, frame = camera.read()
  22. frame = draw_rectangles(frame)
  23. cv2.imshow('Input', frame)
  24. c = cv2.waitKey(1)
  25. if c == 27:
  26. break
  27. camera.release()
  28. cv2.destroyAllWindows()