|
|
@@ -1,9 +1,30 @@ |
|
|
|
import cv2 |
|
|
|
import math |
|
|
|
import itertools as it |
|
|
|
|
|
|
|
DENSITY = 5 |
|
|
|
RED = [0, 0, 255] |
|
|
|
|
|
|
|
|
|
|
|
def draw_rectangles(frame): |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
camera = cv2.VideoCapture(0) |
|
|
|
|
|
|
|
while True: |
|
|
|
ret, frame = camera.read() |
|
|
|
frame = draw_rectangles(frame) |
|
|
|
frame = cv2.rectangle(frame, (0, 0), (100, 100), (255, 0, 0), 2) |
|
|
|
cv2.imshow('Input', frame) |
|
|
|
|
|
|
|
c = cv2.waitKey(1) |
|
|
|