Skip to content

Commit

Permalink
Make redis-buffer and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
inc0 committed Feb 26, 2018
1 parent 7fed5bb commit f8efa89
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
@@ -1,7 +1,7 @@
FROM gcr.io/tensorflow/tensorflow
FROM tensorflow/tensorflow:latest-py3

RUN apt-get update && apt-get -y install git python-opencv wget protobuf-compiler
RUN pip install Flask
RUN pip3 install Flask opencv-python redis ipython

RUN mkdir /mobilenet
RUN git clone https://github.com/tensorflow/models.git
Expand All @@ -15,4 +15,4 @@ WORKDIR /streamapp
COPY . .

EXPOSE 5000
CMD python app.py
CMD python3 app.py
2 changes: 2 additions & 0 deletions app.py
Expand Up @@ -15,6 +15,8 @@ def gen():
while True:
n_frames += 1
frame = get_frame()
if not frame:
continue
fps = n_frames / (time.time() - start)
if n_frames % 10 == 0:
print(str(fps) + " FPS")
Expand Down
8 changes: 5 additions & 3 deletions detection.py
@@ -1,7 +1,9 @@
import cv2
import pickle
import sys

import cv2
import numpy as np
import redis
import tensorflow as tf

sys.path.append(".")
Expand Down Expand Up @@ -74,10 +76,10 @@ def run_inference_for_single_image(image, sess, graph):
output_dict['detection_masks'] = output_dict['detection_masks'][0]
return output_dict

r = redis.StrictRedis(host='redis', port=6379, db=0)

cap = cv2.VideoCapture(0)
def get_frame():
ret, frame = cap.read()
frame = pickle.loads(r.get('img'))
output_dict = run_inference_for_single_image(frame, sess, detection_graph)
vis_util.visualize_boxes_and_labels_on_image_array(
frame,
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,23 @@
---
version: '3'
services:
stream-web:
image: "streamapp"
restart: "always"
ports:
- "5000:5000"
command: "python3 app.py"
links:
- "redis:redis"
stream-buffer:
image: "streamapp"
command: "python3 webcam.py"
restart: "always"
volumes:
- "/dev:/dev"
- "/root/streamapp:/streamapp"
privileged: true
links:
- "redis:redis"
redis:
image: redis
24 changes: 24 additions & 0 deletions webcam.py
@@ -0,0 +1,24 @@
import cv2
import numpy
import socket
from sys import getsizeof
import pickle
import struct
import time
import redis



cap = cv2.VideoCapture('rtsp://192.168.0.107:554/11')
r = redis.StrictRedis(host='redis', port=6379, db=0)
n_frames = 0
start = time.time()
while True:
_, f = cap.read()
n_frames += 1
r.set('img', pickle.dumps(f))
if n_frames % 10 == 0:
print(n_frames / (time.time() - start))
n_frames = 0
start = time.time()

0 comments on commit f8efa89

Please sign in to comment.