From 1d7699f7e1214fba4b6215fe695eff5107029cb6 Mon Sep 17 00:00:00 2001 From: Ed Swarthout Date: Wed, 13 Feb 2019 16:43:50 -0600 Subject: [PATCH] FileVideoStream: do not call transform when stopping Fixes: read_frames_fast.py -v /home/swarthout/packages/sw/opencv/opencv_extra/testdata/highgui/video/big_buck_bunny.wmv [INFO] starting video file thread... Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/usr/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.6/dist-packages/imutils/video/filevideostream.py", line 67, in update frame = self.transform(frame) File "read_frames_fast.py", line 21, in filterFrame frame = imutils.resize(frame, width=450) File "/usr/local/lib/python3.6/dist-packages/imutils/convenience.py", line 69, in resize (h, w) = image.shape[:2] AttributeError: 'NoneType' object has no attribute 'shape' [INFO] elasped time: 0.31 [INFO] approx. FPS: 402.98 Signed-off-by: Ed Swarthout --- imutils/video/filevideostream.py | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/imutils/video/filevideostream.py b/imutils/video/filevideostream.py index f173eb5..ef0b105 100644 --- a/imutils/video/filevideostream.py +++ b/imutils/video/filevideostream.py @@ -50,24 +50,24 @@ def update(self): # reached the end of the video file if not grabbed: self.stopped = True - - # if there are transforms to be done, might as well - # do them on producer thread before handing back to - # consumer thread. ie. Usually the producer is so far - # ahead of consumer that we have time to spare. - # - # Python is not parallel but the transform operations - # are usually OpenCV native so release the GIL. - # - # Really just trying to avoid spinning up additional - # native threads and overheads of additional - # producer/consumer queues since this one was generally - # idle grabbing frames. - if self.transform: - frame = self.transform(frame) - - # add the frame to the queue - self.Q.put(frame) + else: + # if there are transforms to be done, might as well + # do them on producer thread before handing back to + # consumer thread. ie. Usually the producer is so far + # ahead of consumer that we have time to spare. + # + # Python is not parallel but the transform operations + # are usually OpenCV native so release the GIL. + # + # Really just trying to avoid spinning up additional + # native threads and overheads of additional + # producer/consumer queues since this one was generally + # idle grabbing frames. + if self.transform: + frame = self.transform(frame) + + # add the frame to the queue + self.Q.put(frame) else: time.sleep(0.1) # Rest for 10ms, we have a full queue