-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
68 lines (54 loc) · 1.3 KB
/
test.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
#coding:utf-8
import cv2
import classify
from numpy import *
import cv
cap = cv2.VideoCapture(0)
cap.set(cv.CV_CAP_PROP_FRAME_WIDTH, 1200);
cap.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 900);
size=3.5
height=26*size
width=19*size
threth=140
syakin=cv2.imread("./pu.png")
while True:
ret, frame = cap.read()
#10msecキー入力待ち
k = cv2.waitKey(10)
#Escキーを押されたら終了
if k == 27:
break
if k==ord("k"):
size+=0.1
if k==ord("s"):
size-=0.1
print size
if k==ord("c"):
cv2.imwrite("tmp.png",hai)
for y in range(96):
for x in range(369):
frame[y+340,x+150]=syakin[y,x]
cv2.imshow('camera capture', frame)
tin=cv2.waitKey(10)
print "captured."
res=classify.classify_majang("./tmp.png",140)
classify.show_result("./tmp.png",res)
if k==ord("u"):
threth+=5
print threth
if k==ord("d"):
threth-=5
print threth
#frameを表示
x,y=300,200
height=26*size
width=19*size
binary=cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
binary=cv2.threshold(binary, threth, 255, cv2.THRESH_BINARY)[1]
cv2.rectangle(binary,(x,y),(int(x+width),int(y+height)),(0,0,255),2)
cv2.rectangle(frame,(x,y),(int(x+width),int(y+height)),(0,0,255),2)
cv2.imshow('camera capture', frame)
hai=frame[y:int(y+height),x:int(x+width)]
#キャプチャを終了
cap.release()
cv2.destroyAllWindows()