-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroomg.py
More file actions
80 lines (67 loc) · 1.98 KB
/
Copy pathroomg.py
File metadata and controls
80 lines (67 loc) · 1.98 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
import sys
import time
import numpy
import collections
from tqdm import tqdm
args = sys.argv
filename = args[1]
video = cv2.VideoCapture(filename)
if not video.isOpened():
print("c('o'c)")
print("plz {}".format(filename))
sys.exit()
h = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
w = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
f = 0 #int(video.get(cv2.CAP_PROP_FRAME_COUNT))
frame = []
while True:
ret, tmp = video.read()
if not ret:
break
f += 1
frame.append(tmp)
print("c('-'c)")
print("-" * 50)
print("Height:{}\nWidht:{}\nFrame:{}".format(h, w, f))
print("-" * 50)
omg = int(input("omg:"))
print("-" * 50)
omgc = 0
image = [[0] * w for i in range(h)]
bar = tqdm(total = h * w)
bar.set_description('Progress')
start = time.time()
#"""
for i in range(h):
for j in range(w):
colors = []
most = []
n = -1
for k in range(f):
colors.append(str(frame[k][i][j].tolist()))
for k in (collections.Counter(colors).most_common()[0][0]).replace("[", "").replace("]", "").split(', '):
most.append(int(k))
while True:
least = []
for k in (collections.Counter(colors).most_common()[n][0]).replace("[", "").replace("]", "").split(', '):
least.append(int(k))
n -= 1
if most == least:
least = []
for k in (collections.Counter(colors).most_common()[-1][0]).replace("[", "").replace("]", "").split(', '):
least.append(int(k))
break
if abs(sum(most) - sum(least)) > omg:
omgc += 1
break
image[i][j] = numpy.array(least)
bar.update(1)
#print("{}/{}:{:.2f}s".format(i + 1, h, time.time() - start))
#"""
bar.close()
print("omgc:{}".format(omgc))
print("Time:{:.2f}".format(time.time() - start))
print("-" * 50)
cv2.imwrite('{}_room_{}.png'.format(filename.replace(".mp4", ""), omg), numpy.array(image))
print("b(^0^b)")