-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.py
31 lines (26 loc) · 826 Bytes
/
camera.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
import cv2
import numpy as np
from cnn import CNN
import os
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
self.nn = CNN()
self.model = None
if os.path.exists('./model.h5'):
print 'Model Already Exist'
print '--------------------'
self.model = self.nn.load_model()
else:
print 'Model Does Not Exist'
print '--------------------'
self.model = self.nn.create_cnn_model()
def __del__(self):
self.video.release()
def get_frame(self):
_, fr = self.video.read()
frame = np.copy(fr)
frame = self.nn.data_frame(frame)
self.nn.predict_frame(self.model, frame)
_, jpeg = cv2.imencode('.jpg', fr)
return jpeg.tobytes()