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.

36 lines
756B

  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. height, width, d = frame.shape
  8. n = DENSITY
  9. m = math.ceil(n * (height / width))
  10. dx = width / n
  11. dy = height / m
  12. for x, y in it.product(range(n), range(n)):
  13. sp = (int(x * dx), int(y * dy))
  14. ep = (int(x * dx + dx), int(y * dy + dy))
  15. frame = cv2.rectangle(frame, sp, ep, (255, 0, 0))
  16. return frame
  17. camera = cv2.VideoCapture(0)
  18. while True:
  19. ret, frame = camera.read()
  20. frame = draw_rectangles(frame)
  21. frame = cv2.rectangle(frame, (0, 0), (100, 100), (255, 0, 0), 2)
  22. cv2.imshow('Input', frame)
  23. c = cv2.waitKey(1)
  24. if c == 27:
  25. break
  26. camera.release()
  27. cv2.destroyAllWindows()