-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac_camera_app.py
More file actions
34 lines (27 loc) · 1.02 KB
/
mac_camera_app.py
File metadata and controls
34 lines (27 loc) · 1.02 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
__author__ = 'jpatdalton'
'''
This file is a simple camera application that can be run on Mac OS X (and perhaps other operating systems).
'''
import time
import cv2
import predictor
import tensorflow as tf
def execute(model_file):
"""This function creates a OpenCV video capture on a computer's camera. It then loads the predictor's graph and takes images every 4 seconds.
Predictions for each image are printed to the terminal
Args:
model_file: This is the file that contains a trained model on the SVHN dataset.
"""
time.sleep(2) # give camera time to get setup - it will throw an error if not
cap = cv2.VideoCapture(0)
time.sleep(2)
with tf.Session(graph=predictor.graph) as session:
saver = tf.train.Saver()
saver.restore(session, model_file)
print("Model restored.")
for i in range(100):
# Capture frame-by-frame
time.sleep(4)
ret, frame = cap.read()
predictor.process_array(frame, session)
cap.release()