Skip to content

Commit 70091b9

Browse files
committed
basic setup
- now allows flag for stream source - setup environments to work for me - got linux environment working - setup infrastructure for rtmp server stream object.
1 parent e5341f7 commit 70091b9

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

environment-linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- freetype=2.5.5=2
88
- icu=54.1=0
99
- jbig=2.1=0
10-
- jlaura::opencv3=3.0.0=py35_0
10+
- menpo::opencv3=3.1.0=py35_0
1111
- jpeg=9b=0
1212
- libpng=1.6.27=0
1313
- libtiff=4.0.6=3

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- freetype=2.5.5=2
88
- icu=54.1=0
99
- jbig=2.1=0
10-
- jlaura::opencv3=3.0.0=py35_0
10+
- menpo::opencv3=3.1.0=py35_0
1111
- jpeg=9b=0
1212
- libpng=1.6.27=0
1313
- libtiff=4.0.6=3

object_detection_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def worker(input_q, output_q):
8585

8686
if __name__ == '__main__':
8787
parser = argparse.ArgumentParser()
88+
parser.add_argument('-str', '--stream', dest="is_stream", action="store_true")
8889
parser.add_argument('-src', '--source', dest='video_source', type=int,
8990
default=0, help='Device index of the camera.')
9091
parser.add_argument('-wd', '--width', dest='width', type=int,
@@ -104,6 +105,12 @@ def worker(input_q, output_q):
104105
output_q = Queue(maxsize=args.queue_size)
105106
pool = Pool(args.num_workers, worker, (input_q, output_q))
106107

108+
109+
if (args.is_stream):
110+
print('Reading from rtmp stream.')
111+
else:
112+
print('Reading from webcam.')
113+
107114
video_capture = WebcamVideoStream(src=args.video_source,
108115
width=args.width,
109116
height=args.height).start()

utils/app_utils.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ def fps(self):
4141
return self._numFrames / self.elapsed()
4242

4343

44+
class RTMPVideoStream:
45+
def __init__(self, src, width, height):
46+
# initialize the video camera stream and read the first frame
47+
# from the stream
48+
self.stream = cv2.VideoCapture(src)
49+
self.stream.set(cv2.CAP_PROP_FRAME_WIDTH, width)
50+
self.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
51+
(self.grabbed, self.frame) = self.stream.read()
52+
53+
# initialize the variable used to indicate if the thread should
54+
# be stopped
55+
self.stopped = False
56+
57+
def start(self):
58+
# start the thread to read frames from the video stream
59+
Thread(target=self.update, args=()).start()
60+
return self
61+
62+
def update(self):
63+
# keep looping infinitely until the thread is stopped
64+
while True:
65+
# if the thread indicator variable is set, stop the thread
66+
if self.stopped:
67+
return
68+
69+
# otherwise, read the next frame from the stream
70+
(self.grabbed, self.frame) = self.stream.read()
71+
72+
def read(self):
73+
# return the frame most recently read
74+
return self.frame
75+
76+
def stop(self):
77+
# indicate that the thread should be stopped
78+
self.stopped = True
79+
4480
class WebcamVideoStream:
4581
def __init__(self, src, width, height):
4682
# initialize the video camera stream and read the first frame

0 commit comments

Comments
 (0)