|
- import cv2
- import math
- import itertools as it
-
- DENSITY = 5
- RED = [0, 0, 255]
-
-
- def draw_rectangles(frame):
- """ Draw some rectangles on top of the image """
- height, width, d = frame.shape
- n = DENSITY
- m = math.ceil(n * (height / width))
- dx = width / n
- dy = height / m
- for x, y in it.product(range(n), range(n)):
- sp = (int(x * dx), int(y * dy))
- ep = (int(x * dx + dx), int(y * dy + dy))
- frame = cv2.rectangle(frame, sp, ep, (255, 0, 0))
- return frame
-
-
- if __name__ == '__main__':
- camera = cv2.VideoCapture(0)
-
- while True:
- ret, frame = camera.read()
- frame = draw_rectangles(frame)
- cv2.imshow('Input', frame)
-
- c = cv2.waitKey(1)
- if c == 27:
- break
-
- camera.release()
- cv2.destroyAllWindows()
|