-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
107 lines (87 loc) · 2.34 KB
/
main.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
"""
Methods:
* Background substraction + HSV
* HAAR cascades
Last updated: 06-05-2014
"""
import cv2
import os
import sys
import time
from tracker import TrackerAL, StateTracker
from transformer import Transformer
from haartrack import FaceTracker, Face, Hand, HandTracker
from hand_picker import HandPicker
from main_utils import draw_boxes, \
init_camera, \
release_camera
from calibration2 import Calibration
from calibrationHaar import CalibrationHaar
from config import HEIGHT, WIDTH
c = init_camera()
def read_image():
#TODO: implement me
return None
def read_camera():
_, f = c.read()
if HEIGHT != 480:
f = cv2.resize(f, (WIDTH, HEIGHT))
return f
def main_viola_jones():
track = TrackerAL()
hnd = HandTracker()
while(1):
_,f = c.read()
small = cv2.resize(f, (320, 240))
hnd.update(small)
hands = hnd.hands
boxes = track.pbb(hands)
box = HandPicker.distinguish(small, boxes)
if box:
draw_boxes(small, [box])
cv2.imshow('IMG', small)
k = cv2.waitKey(20)
if k == 27:
break
def run_calibration():
"""
Runs calibration.
"""
clbr = Calibration()
cnt = 0
while (not clbr.end):
img = read_camera()
if img is None:
cnt += 1
clbr.update(img)
if cnt > 100:
return None
return clbr
#version with Substraction and HSV detection
def main_system(profile=0):
clbr = run_calibration()
print "*******", clbr.conf_h, clbr.conf_yv, clbr.thr, clbr.light, "*******"
trf = Transformer(clbr.light, clbr.conf_h, clbr.conf_yv, clbr.thr)
trf.turn_on_bayes_classifier(clbr.pdf_cmp_h, clbr.pdf_cmp_v)
track = StateTracker()
while (1):
f = read_camera()
move_cue = trf.move_cue(f)
skin_cue = trf.skin_classifier(f)
skin_cue = trf.clean_whole_image(skin_cue)
final = cv2.bitwise_and(skin_cue, move_cue)
track.update(final)
info = track.follow(f)
cv2.imshow('IMG', f)
cv2.imshow('SKIN FINAL', final)
k = cv2.waitKey(20)
if k == 27:
break
# debug & profile part
if profile > 0:
profile -= 1
if profile == 0:
break
if __name__ == "__main__":
main_system()
release_camera(c)