-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.py
More file actions
80 lines (70 loc) · 6.52 KB
/
rectangle.py
File metadata and controls
80 lines (70 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import cv2
def Locking_Rectangle(frame):
bgr1 = (120, 120, 120)
bgr = (0, 255, 0)
bgr2 = (0, 184, 255)
disx1, disx2, disy1, disy2 = int(frame.shape[1] * 0.25), int(frame.shape[1] * 0.75), int(
frame.shape[0] * 0.10), int(frame.shape[0] * 0.90)
cv2.rectangle(frame, (disx1, disy1), (disx2, disy2), (0, 0, 255), 1)
centerOfRectx = int((disx1 + disx2) / 2)
centerOfRecty = int((disy1 + disy2) / 2)
centerOfRect = (int((disx1 + disx2) / 2), int((disy1 + disy2) / 2))
cv2.line(frame, (centerOfRectx, disy1), (centerOfRectx, disy2), bgr1, 1)
cv2.line(frame, (disx1, centerOfRecty), (disx2, centerOfRecty), bgr1, 1)
cv2.line(frame, (centerOfRect), (centerOfRectx - 20, centerOfRecty), bgr1, 2)
cv2.line(frame, (centerOfRect), (centerOfRectx, centerOfRecty + 20), bgr1, 2)
cv2.line(frame, (centerOfRect), (centerOfRectx + 20, centerOfRecty), bgr1, 2)
cv2.line(frame, (centerOfRect), (centerOfRectx, centerOfRecty - 20), bgr1, 2)
cv2.line(frame, (centerOfRectx + 40, centerOfRecty + 5), (centerOfRectx + 40, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 40, centerOfRecty - 5), (centerOfRectx + 40, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 60, centerOfRecty + 5), (centerOfRectx + 60, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 60, centerOfRecty - 5), (centerOfRectx + 60, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 80, centerOfRecty + 5), (centerOfRectx + 80, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 80, centerOfRecty - 5), (centerOfRectx + 80, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 100, centerOfRecty + 5), (centerOfRectx + 100, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 100, centerOfRecty - 5), (centerOfRectx + 100, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 120, centerOfRecty + 5), (centerOfRectx + 120, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 120, centerOfRecty - 5), (centerOfRectx + 120, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 140, centerOfRecty + 5), (centerOfRectx + 140, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 140, centerOfRecty - 5), (centerOfRectx + 140, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 40, centerOfRecty + 5), (centerOfRectx - 40, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 40, centerOfRecty - 5), (centerOfRectx - 40, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 60, centerOfRecty + 5), (centerOfRectx - 60, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 60, centerOfRecty - 5), (centerOfRectx - 60, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 80, centerOfRecty + 5), (centerOfRectx - 80, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 80, centerOfRecty - 5), (centerOfRectx - 80, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 100, centerOfRecty + 5), (centerOfRectx - 100, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 100, centerOfRecty - 5), (centerOfRectx - 100, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 120, centerOfRecty + 5), (centerOfRectx - 120, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 120, centerOfRecty - 5), (centerOfRectx - 120, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 140, centerOfRecty + 5), (centerOfRectx - 140, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx - 140, centerOfRecty - 5), (centerOfRectx - 140, centerOfRecty), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 40), (centerOfRectx, centerOfRecty - 40), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 40), (centerOfRectx, centerOfRecty - 40), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 60), (centerOfRectx, centerOfRecty - 60), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 60), (centerOfRectx, centerOfRecty - 60), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 80), (centerOfRectx, centerOfRecty - 80), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 80), (centerOfRectx, centerOfRecty - 80), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 100), (centerOfRectx, centerOfRecty - 100), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 100), (centerOfRectx, centerOfRecty - 100), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 120), (centerOfRectx, centerOfRecty - 120), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 120), (centerOfRectx, centerOfRecty - 120), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 140), (centerOfRectx, centerOfRecty - 140), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 140), (centerOfRectx, centerOfRecty - 140), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty - 160), (centerOfRectx, centerOfRecty - 160), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty - 160), (centerOfRectx, centerOfRecty - 160), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 40), (centerOfRectx, centerOfRecty + 40), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 40), (centerOfRectx, centerOfRecty + 40), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 60), (centerOfRectx, centerOfRecty + 60), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 60), (centerOfRectx, centerOfRecty + 60), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 80), (centerOfRectx, centerOfRecty + 80), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 80), (centerOfRectx, centerOfRecty + 80), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 100), (centerOfRectx, centerOfRecty + 100), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 100), (centerOfRectx, centerOfRecty + 100), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 120), (centerOfRectx, centerOfRecty + 120), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 120), (centerOfRectx, centerOfRecty + 120), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 140), (centerOfRectx, centerOfRecty + 140), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 140), (centerOfRectx, centerOfRecty + 140), bgr2, 1)
cv2.line(frame, (centerOfRectx + 5, centerOfRecty + 160), (centerOfRectx, centerOfRecty + 160), bgr2, 1)
cv2.line(frame, (centerOfRectx - 5, centerOfRecty + 160), (centerOfRectx, centerOfRecty + 160), bgr2, 1)
return frame,bgr,bgr2,centerOfRect,disx1, disx2, disy1, disy2