代码:
from imutils.video import VideoStream
import cv2
# Read rtsp stream
rtsp = u"rtsp://admin:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9efffaf3f7f0deafaeb0a8aab0afb0adaf" rel="noreferrer noopener nofollow">[email protected]</a>:554/1/h264major"
#vs = VideoStream(src=0).start() # for capturing from webcam
vs = VideoStream(src=rtsp).start()
while True:
frame = vs.read()
# show the output frame
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()
- 我在使用 opencv 的 VideoCapture 时遇到了同样的问题 [ cap.isOpened() returns False ]
- 在两种情况下,即 cv2.VideoCapture(0) 或 VideoStream(src=0).start() 从网络摄像头捕获时,独立可执行文件都可以正常工作
- 当脚本在 python 中运行时,rtsp 流捕获在这两种情况下都可以正常工作,即无需将其转换为独立的可执行文件。
- rtsp 流已在 VLC 播放器上进行测试,运行良好。
- 我正在使用 Python 3.6.2 | OpenCV 3.2.0 |窗口
这可能是由于 RTSP 链接的 utf-8 等编码问题造成的吗?还有其他选择吗?
已解决:在我的可执行文件旁边包含 opencv_ffmpeg320_64.dll。
最佳答案
在我的可执行文件旁边包含 opencv_ffmpeg320_64.dll。 或者,将该 dll 文件复制到 python 目录中的 DLLs 文件夹
关于python - 使用 pyinstaller 将脚本转换为独立可执行文件时捕获 RTSP 流失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47475130/