- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 opencv-python(版本 4.4.0.46)python 版本 3.8.5 来捕获我的网络摄像机流,但是,我无法读取视频帧。这是我的代码:
import cv2
# cap = cv2.VideoCapture("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov")
cap = cv2.VideoCapture("rtsp://admin:xxx@xxx/Streaming/Channels/1")
print(cap.isOpened())
ret,frame = cap.read()
print(ret)
while ret:
ret,frame = cap.read()
print(ret)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
在我的代码中,当我使用我的 IPC 流时,我得到“print(cap.isOpened())”为真,而“cap.read()”返回假。但是,当它切换到“BigBuckBunny_115k”流时,一切正常,我可以得到框架图片。
有人可能会说你的IPC应该损坏了。不过我试过用ffmpeg抓视频,可以很方便的得到帧图。我的代码:
ffmpeg -i "rtsp://admin:xxx@xxx/Streaming/Channels/1" -y -f image2 -r 1/1 img%03d.jpg
使用python抓取视频,如上得到“False”,但是没有打印ant错误日志,让我很难解决问题。所以我改为使用java,并使用opencv-4.4.0.so作为库,我的代码:
VideoCapture videoCapture = new VideoCapture();
// set the exception mode true so that it can print stack trace when error
videoCapture.setExceptionMode(true);
boolean openStatus = videoCapture.open("rtsp://admin:xxx@xxx/Streaming/Channels/1");
log.info("open rtsp status: {}", openStatus);
int i = 0;
status = true;
while (openStatus && status) {
Mat mat = new Mat();
videoCapture.read(mat);
Imgcodecs.imwrite("../" + i + ".png", mat);
i++;
}
通过运行这段代码,我得到了异常:org.opencv.core.CvException: cv::Exception: OpenCV(4.4.0)/xxx/opencv-4.4.0/modules/videoio/src/cap.cpp: 177:错误:(-2:未指定错误)无法在函数“打开”中打开“rtsp://admin:xxx@xxx/Streaming/Channels/1”。上面的异常日志对解决问题没有帮助,"-2:Unspecified error"是什么意思?
忘了说我的runtime是CentOS 7.5(内核版本3.10.0-862.el7.x86_64)。然后我又换了一个同样opencv-python版本和CentOS版本的服务器。奇怪的是,在这个新服务器上,使用相同的 opencv 代码,我现在可以获取视频帧了。
第一个问题,有没有相关的资料可以引用?第二个问题是,我该如何解决这个问题。第三个问题,为什么在不同的服务器上表现不一样,我的第一个服务器上是否有任何系统配置错误,比如网络配置?
2021.01.07 更新
感谢 antoine 为我提供有关 OpenCV 后端的信息。我尝试使用以下代码打印 python-opencv 构建信息。
import cv2
print(cv2.getBuildInformation())
在我拥有的两台服务器上(其中一台可以读取视频流,另一台不能),我得到的控制台打印结果完全一样。这是打印品:
General configuration for OpenCV 4.4.0 =====================================
Version control: 4.4.0-dirty
Platform:
Timestamp: 2020-11-03T00:52:03Z
Host: Linux 4.15.0-1077-gcp x86_64
CMake: 3.18.2
CMake generator: Unix Makefiles
CMake build tool: /bin/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (15 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (4 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (29 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (4 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
C/C++:
Built as dynamic libs?: NO
C++ standard: 11
C++ Compiler: /usr/lib/ccache/compilers/c++ (ver 9.3.1)
C++ flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/lib/ccache/compilers/cc
C flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/root/ffmpeg_build/lib -Wl,--gc-sections -Wl,--as-needed
Linker flags (Debug): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/root/ffmpeg_build/lib -Wl,--gc-sections -Wl,--as-needed
ccache: YES
Precompiled headers: NO
Extra dependencies: ade Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent /lib64/libpng.so /lib64/libz.so dl m pthread rt
3rdparty dependencies: ittnotify libprotobuf libjpeg-turbo libwebp libtiff libjasper IlmImf quirc ippiw ippicv
OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java js python2 ts
Applications: -
Documentation: NO
Non-free algorithms: NO
GUI:
QT: YES (ver 5.15.0)
QT OpenGL support: NO
GTK+: NO
VTK support: NO
Media I/O:
ZLib: /lib64/libz.so (ver 1.2.7)
JPEG: libjpeg-turbo (ver 2.0.5-62)
WEBP: build (ver encoder: 0x020f)
PNG: /lib64/libpng.so (ver 1.5.13)
TIFF: build (ver 42 - 4.0.10)
JPEG 2000: build Jasper (ver 1.900.1)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.109.100)
avformat: YES (58.61.100)
avutil: YES (56.60.100)
swscale: YES (5.8.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
Parallel framework: pthreads
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2020.0.0 Gold [2020.0.0]
at: /tmp/pip-req-build-99ib2vsi/_skbuild/linux-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_lnx/icv
Intel IPP IW: sources (2020.0.0)
at: /tmp/pip-req-build-99ib2vsi/_skbuild/linux-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_lnx/iw
Lapack: NO
Eigen: NO
Custom HAL: NO
Protobuf: build (3.5.1)
OpenCL: YES (no extra features)
Include path: /tmp/pip-req-build-99ib2vsi/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python 3:
Interpreter: /opt/python/cp38-cp38/bin/python (ver 3.8.6)
Libraries: libpython3.8.a (ver 3.8.6)
numpy: /tmp/pip-build-env-qru8fff1/overlay/lib/python3.8/site-packages/numpy/core/include (ver 1.17.3)
install path: python
Python (for build): /bin/python2.7
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: /tmp/pip-req-build-99ib2vsi/_skbuild/linux-x86_64-3.8/cmake-install
-----------------------------------------------------------------
在打印中,我找到了信息:
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.109.100)
avformat: YES (58.61.100)
avutil: YES (56.60.100)
swscale: YES (5.8.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
似乎我的两台服务器都有 FFMPEG 而没有 GStreamer。那么,是否还有其他原因可能导致这种差异呢?
顺便说一句,我试过将 API 首选项传递给构造函数,如下所示:
cap = cv2.VideoCapture("rtsp://admin:xxx@xxx/Streaming/Channels/1", cv2.CAP_FFMPEG)
但是传参也没有解决问题,我也无法读取视频帧。
最佳答案
OpenCV 使用不同的后端来读取/写入/编码/解码视频流,具体取决于您机器上安装的内容以及您使用 OpenCV 构建的内容。这可以解释为什么即使使用相同的操作系统和 OpenCV 版本,您在不同的服务器上也会得到不同的结果:您可以在一个而不是另一个上安装 GStreamer。
您可以在 OpenCV Documentation 上找到有关这些后端的一些信息.
Linux 上的 IIRC,OpenCV 使用 GStreamer 作为默认后端,并且您使用 FFMPEG 测试了您的流。 OpenCV 也可以使用 FFMPEG,尝试将 cv.CAP_FFMPEG
作为您的 API 偏好传递给 cv.VideoCapture
构造函数:
cap = cv2.VideoCapture("rtsp://admin:xxx@xxx/Streaming/Channels/1", cv.CAP_FFMPEG)
关于冗长,OpenCV videoio 模块并不那么冗长。但是一些后端是,例如,您可以使用 GST_DEBUG
环境变量增加 GStreamer 的详细程度,请参阅 GStreamer documentation .对于 FFMPEG,您可以使用 FFREPORT
环境变量或一些 AV_LOG*
环境变量,请参阅 FFMPEG documentation .
关于OpenCV videocapture读取摄像头rtsp错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65574163/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!