-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop_base2.py
123 lines (97 loc) · 2.26 KB
/
loop_base2.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import numpy as np
import cv2
frame = np.zeros((600,600,3))
frame[0:200,200:400] = [0,0,255]
frame[0:150,250:350] = [0,0,0]
cv2.imshow('orig',frame)
pixcol = [0,0,255]
l = []
thresh = 100
bound = []
b = 0
#video_path = 'vid.mp4'
#cap = cv2.VideoCapture(0)
#_,frame2 = cap.read()
#while True:
# _,framecap.read()
for i in range(frame.shape[1]):
col = frame[:,i]
l.append(np.sum([(col[j]==pixcol).all() for j in range(0,frame.shape[0],2)]))
print(l)
for ind,val in enumerate(l):
if len(bound)!=4:
if not b:
if val >= thresh:
bound.append(ind*2)
b=1
else:import numpy as np
import cv2
import time
frame = np.zeros((600,600,3))
frame[0:200,200:400] = [0,0,255]
frame[0:150,250:350] = [0,0,0]
cv2.imshow('orig',frame)
pixcol = [0,0,255]
l = []
thresh = 100
bound = []
b = 0
#video_path = 'vid.mp4'
#cap = cv2.VideoCapture(0)
#_,frame2 = cap.read()
#while True:
# _,framecap.read()
tik = time.time()
for i in range(0,frame.shape[1],2):
col = frame[:,i]
l.append(np.sum([(col[j]==pixcol).all() for j in range(frame.shape[0])]))
print(len(l))
for ind,val in enumerate(l):
if len(bound)!=4:
if not b:
if val >= thresh:
bound.append(ind*2)
b=1
else:
if val < thresh:
bound.append(ind*2)
b=0
col = frame[:,bound[0]+5]
r = pixcol
i = 0
while i in range(frame.shape[0]):
if not (frame[i,bound[0]+5] == pixcol).all():
break
i+=1
print(bound)
rup = (bound[0],0)
rdown = (bound[1],i)
lup = (bound[2],0)
ldown = (bound[3],i)
cv2.rectangle(frame,rup,rdown,[255,0,0],3)
cv2.rectangle(frame,lup,ldown,[255,0,0],3)
tok = time.time()
tiktok = tok - tik
print(tiktok)
cv2.imshow('win',frame)
cv2.waitKey(0)
#if cv2.waitKey(1) & 0xFF == ord('q'):
# break
#cap.release()
cv2.destroyAllWindows()
if val < thresh:
bound.append(ind*2)
b=0
print(bound)
rup = (bound[0],0)
rdown = (bound[1],200)
lup = (bound[2],0)
ldown = (bound[3],200)
cv2.rectangle(frame,rup,rdown,[255,0,0],3)
cv2.rectangle(frame,lup,ldown,[255,0,0],3)
cv2.imshow('win',frame)
cv2.waitKey(0)
#if cv2.waitKey(1) & 0xFF == ord('q'):
# break
#cap.release()
cv2.destroyAllWindows()