-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
70 lines (47 loc) · 1.36 KB
/
timer.py
File metadata and controls
70 lines (47 loc) · 1.36 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
import cv2
import pyocr
from PIL import Image
import sys
argv = sys.args
sec = {}
# 動画が30fpsの場合
tick = 1.0/30.0
engines = pyocr.get_available_tools()
engine = engines[0]
cap = cv2.VideoCapture(argv[1])
# 無限ループ
while(True):
ret, frame = cap.read()
if not ret: # 終了処理
break
# 画像のサイズを取得,表示。グレースケールの場合,shape[:2]
h, w, _ = frame.shape[:3]
# ページ番号をフォーカス
# 要:自動化
w_center = (w//100)*93
h_center = (h//1000)*999
# # カメラ画像の整形
im = frame[h_center:h_center+60, w_center-30:w_center+30] # トリミング
# 判定結果を上位3番目まで表示させる
cv2.imwrite('checkpt.png', im)
num = engine.image_to_string(Image.open('checkpt.png'), lang='eng', builder=pyocr.builders.DigitBuilder(tesseract_layout=6))
print(num) # 「Test Message」が出力される
if num.isdecimal():
p_num = int(num)
else:
p_num = -1
if p_num == -1:
continue
elif p_num in sec:
sec[p_num] += tick
else:
sec[p_num] = tick
sec = sorted(sec.items())
sec = dict((x, y) for x, y in sec)
print(sec)
sum = 0.0
for i in sec.values():
sum += i
print(sum)
cap.release() # カメラを解放
cv2.destroyAllWindows() # ウィンドウを消す