带有 python3 和 CUDA 的 OpenCV 4.2.0:cv2.VideoCapture() 上的段错误
OpenCV 4.2.0 with python3 and CUDA : Segfault on cv2.VideoCapture()
我在使用 OpenCV 时遇到了一个问题,这个问题已经困扰我好几天了:它在调用 cv2.VideoCapture()
函数时出现段错误。
启动脚本时(使用 GDB):
extract-all_1 | Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
extract-all_1 | 0x00007f83857fe33b in bool pyopencv_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(_object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, ArgInfo const&) [clone .isra.1286] ()
extract-all_1 | from /usr/lib/python3/dist-packages/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so
extract-all_1 | (gdb) quit
When running my script without GDB, the container exits with code 139
我发现调用 "cv2.VideoCapture()" 函数时出现了问题:
def perform_video_extraction(video_path):
input_movie = cv2.VideoCapture(video_path)
nb_total_frames = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))
[...]
提示:
- 我处理 MP4 视频文件
- 我尝试将 >30fps 的视频压缩到 25fps
- 我尝试过 OpenCV 3.4.9、4.1.0、4.1.1、4.1.2、4.2.0 和 4.3.0(pip 安装)
- 我尝试从源代码编译 OpenCV 4.2.0 和 4.3.0
- 我已经用 CUDA 10.0、10.1 和 10.2 连续尝试了上面的每个版本:每个案例的每个版本都会产生相同的错误
- 使用 CPU(非 cuda)版本的 OpenCV 时不会重现此段错误
这是我的 Docker 文件(CUDA 10.2 和从源代码构建的 OpenCV 4.2.0):https://pastebin.com/raw/a42wtcRG
这是 cmake
摘要构建 returns 的内容:https://pastebin.com/raw/SFPUakyL
我的配置:
- Ubuntu 18.04
- 英伟达 Docker (CUDA 10.2, CUDNN 7, Ubuntu 18.04, devel)
- Python 3.6
你对调试这个问题有什么建议吗?
谢谢
我设法调试了问题。由于愚蠢的 编码 问题。
添加:
ENV LANG C.UTF-8
我的 Dockerfile 设法使容器成为 运行(我原来的 pastebin 提到了这一行,但在仔细检查后,我没有)。
由于来自 GDB 的更准确的回溯,我能够找到这个想法:
root@f42846d26d89:/opencv-4.2.0/build# gdb --args python3 -u /usr/app/scripts/extract.py
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python3 -u /usr/app/scripts/extract.py
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[...]
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
getUnicodeString (str="", obj=<optimized out>) at /opencv-4.2.0/modules/python/src2/pycompat.hpp:69
69 if (PyBytes_Check(bytes))
(gdb) backtrace
#0 0x00007f2959a1433b in getUnicodeString (str="", obj=<optimized out>) at /opencv-4.2.0/modules/python/src2/pycompat.hpp:69
#1 0x00007f2959a1433b in pyopencv_to<std::__cxx11::basic_string<char> >(PyObject*, cv::String&, ArgInfo const&) (obj=<optimized out>, value="", info=...)
at /opencv-4.2.0/modules/python/src2/cv2.cpp:731
#2 0x00007f2959dd6a2d in pyopencv_cv_VideoCapture_VideoCapture(pyopencv_VideoCapture_t*, PyObject*, PyObject*) (self=0x7f2965344190, args=0x7f296307c3c8, kw=0x0)
at /opencv-4.2.0/build/modules/python_bindings_generator/pyopencv_generated_types_content.h:21272
#3 0x0000000000551b81 in ()
#4 0x00000000005aa6ec in _PyObject_FastCallKeywords ()
#5 0x000000000050abb3 in ()
#6 0x000000000050c5b9 in _PyEval_EvalFrameDefault ()
#7 0x0000000000509d48 in ()
#8 0x000000000050aa7d in ()
#9 0x000000000050c5b9 in _PyEval_EvalFrameDefault ()
#10 0x0000000000508245 in ()
#11 0x000000000050b403 in PyEval_EvalCode ()
#12 0x0000000000635222 in ()
#13 0x00000000006352d7 in PyRun_FileExFlags ()
#14 0x0000000000638a8f in PyRun_SimpleFileExFlags ()
#15 0x0000000000639631 in Py_Main ()
#16 0x00000000004b0f40 in main ()
(gdb) list
64 {
65 bool res = false;
66 if (PyUnicode_Check(obj))
67 {
68 PyObject * bytes = PyUnicode_AsUTF8String(obj);
69 if (PyBytes_Check(bytes))
70 {
71 const char * raw = PyBytes_AsString(bytes);
72 if (raw)
73 {
(gdb)
/opencv-4.2.0
being my install path
我的文件名似乎没有采用正确的编码格式。
最后,我指定 pip install
ing python 绑定直接工作得很好,现在已经进行了此修改。
我在使用 OpenCV 时遇到了一个问题,这个问题已经困扰我好几天了:它在调用 cv2.VideoCapture()
函数时出现段错误。
启动脚本时(使用 GDB):
extract-all_1 | Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
extract-all_1 | 0x00007f83857fe33b in bool pyopencv_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(_object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, ArgInfo const&) [clone .isra.1286] ()
extract-all_1 | from /usr/lib/python3/dist-packages/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so
extract-all_1 | (gdb) quit
When running my script without GDB, the container exits with code 139
我发现调用 "cv2.VideoCapture()" 函数时出现了问题:
def perform_video_extraction(video_path):
input_movie = cv2.VideoCapture(video_path)
nb_total_frames = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))
[...]
提示:
- 我处理 MP4 视频文件
- 我尝试将 >30fps 的视频压缩到 25fps
- 我尝试过 OpenCV 3.4.9、4.1.0、4.1.1、4.1.2、4.2.0 和 4.3.0(pip 安装)
- 我尝试从源代码编译 OpenCV 4.2.0 和 4.3.0
- 我已经用 CUDA 10.0、10.1 和 10.2 连续尝试了上面的每个版本:每个案例的每个版本都会产生相同的错误
- 使用 CPU(非 cuda)版本的 OpenCV 时不会重现此段错误
这是我的 Docker 文件(CUDA 10.2 和从源代码构建的 OpenCV 4.2.0):https://pastebin.com/raw/a42wtcRG
这是 cmake
摘要构建 returns 的内容:https://pastebin.com/raw/SFPUakyL
我的配置:
- Ubuntu 18.04
- 英伟达 Docker (CUDA 10.2, CUDNN 7, Ubuntu 18.04, devel)
- Python 3.6
你对调试这个问题有什么建议吗?
谢谢
我设法调试了问题。由于愚蠢的 编码 问题。
添加:
ENV LANG C.UTF-8
我的 Dockerfile 设法使容器成为 运行(我原来的 pastebin 提到了这一行,但在仔细检查后,我没有)。
由于来自 GDB 的更准确的回溯,我能够找到这个想法:
root@f42846d26d89:/opencv-4.2.0/build# gdb --args python3 -u /usr/app/scripts/extract.py
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python3 -u /usr/app/scripts/extract.py
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[...]
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
getUnicodeString (str="", obj=<optimized out>) at /opencv-4.2.0/modules/python/src2/pycompat.hpp:69
69 if (PyBytes_Check(bytes))
(gdb) backtrace
#0 0x00007f2959a1433b in getUnicodeString (str="", obj=<optimized out>) at /opencv-4.2.0/modules/python/src2/pycompat.hpp:69
#1 0x00007f2959a1433b in pyopencv_to<std::__cxx11::basic_string<char> >(PyObject*, cv::String&, ArgInfo const&) (obj=<optimized out>, value="", info=...)
at /opencv-4.2.0/modules/python/src2/cv2.cpp:731
#2 0x00007f2959dd6a2d in pyopencv_cv_VideoCapture_VideoCapture(pyopencv_VideoCapture_t*, PyObject*, PyObject*) (self=0x7f2965344190, args=0x7f296307c3c8, kw=0x0)
at /opencv-4.2.0/build/modules/python_bindings_generator/pyopencv_generated_types_content.h:21272
#3 0x0000000000551b81 in ()
#4 0x00000000005aa6ec in _PyObject_FastCallKeywords ()
#5 0x000000000050abb3 in ()
#6 0x000000000050c5b9 in _PyEval_EvalFrameDefault ()
#7 0x0000000000509d48 in ()
#8 0x000000000050aa7d in ()
#9 0x000000000050c5b9 in _PyEval_EvalFrameDefault ()
#10 0x0000000000508245 in ()
#11 0x000000000050b403 in PyEval_EvalCode ()
#12 0x0000000000635222 in ()
#13 0x00000000006352d7 in PyRun_FileExFlags ()
#14 0x0000000000638a8f in PyRun_SimpleFileExFlags ()
#15 0x0000000000639631 in Py_Main ()
#16 0x00000000004b0f40 in main ()
(gdb) list
64 {
65 bool res = false;
66 if (PyUnicode_Check(obj))
67 {
68 PyObject * bytes = PyUnicode_AsUTF8String(obj);
69 if (PyBytes_Check(bytes))
70 {
71 const char * raw = PyBytes_AsString(bytes);
72 if (raw)
73 {
(gdb)
/opencv-4.2.0
being my install path
我的文件名似乎没有采用正确的编码格式。
最后,我指定 pip install
ing python 绑定直接工作得很好,现在已经进行了此修改。