Always-on computer music
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

3 年前
3 年前
3 年前
1234567891011121314151617181920212223242526272829303132333435
  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()