-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileVideoStream puts an NoneType into the queue #251
Comments
tapani-hopkins
added a commit
to tapani-hopkins/imutils
that referenced
this issue
Nov 11, 2021
When FileVideoStream reaches the end of the file, it takes one more frame (which is NoneType) and tries to transform and add it to the queue. This has also been noted in issue PyImageSearch#251 . This causes an error if the transform expects a valid frame, or if the main script does not expect the last frame in the Queue to be NoneType.
yeah it works, though I add a return instead of continue. Helpful. Thanks |
This fix worked for me as well. Another approach, if someone doesn't want to modify # loop over frames from the video file stream
while fvs.more():
# grab the frame from the threaded video file stream, resize
# it, and convert it to grayscale (while still retaining 3
# channels)
frame = fvs.read()
if frame is not None:
frame = imutils.resize(frame, width=450)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = np.dstack([frame, frame, frame])
# display the size of the queue on the frame
cv2.putText(frame, "Queue Size: {}".format(fvs.Q.qsize()),
(10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
# show the frame and update the FPS counter
cv2.imshow("Frame", frame)
cv2.waitKey(1)
fps.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I read this article and write a code like this (almost the same code as the article showed):
I run this code with
python3 test.py -v video.mp4
and the script does playback the all video but finally an error was thrown out:It seems that a NoneType was fed to the function
imutils.resize()
instead of a available frame. Since all the frames are fetched from the queue in FileVideoStream, I found the reason that causes this error in the implementation of FileVideoStream.In function
update()
ofimutils/video/filevideostream.py
, ifcv2.VideoCapture().read()
faild(that basically means it reached the end of video file), althoughself.stopped
is set to be True,self.Q.put(frame)
in the below is still executed and put a NoneType into the queue. The process won't stop until the next loop start, but in this case it should be stopped immediately, at least before theself.Q.put(frame)
.The original
filevideostream.py
, with all comments and empty lines deleted:I added a
continue
underself.stopped = True
to avoidself.Q.put(frame)
from executing and the error didn't appear any more.I don't know whether it is a bug of FileVideoStream. Maybe this solution will cause another issue. But if someone using FileVideoStream meets the same error then you can try this solution.
The text was updated successfully, but these errors were encountered: