【问题标题】:OpenCV 4.2.0 with python3 and CUDA : Segfault on cv2.VideoCapture()带有 python3 和 CUDA 的 OpenCV 4.2.0:cv2.VideoCapture() 上的段错误
【发布时间】:2020-04-30 22:36:29
【问题描述】:

我遇到了一个困扰我好几天的 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

在没有 GDB 的情况下运行我的脚本时,容器以代码 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 时不会重现此段错误

这是我的 Dockerfile(CUDA 10.2 和 OpenCV 4.2.0 从源代码构建):https://pastebin.com/raw/a42wtcRG

这是cmake 摘要构建返回的内容:https://pastebin.com/raw/SFPUakyL

我的配置:

您对调试此问题有什么建议吗?

谢谢

【问题讨论】:

    标签: docker opencv python-3.6 nvidia-docker


    【解决方案1】:

    我设法调试了这个问题。由于一个愚蠢的编码问题。

    添加:

    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 是我的安装路径

    我的文件名似乎不是正确的编码格式。

    最后,我指定pip installing python 绑定直接工作得很好,现在已经带来了这个修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2020-09-20
      • 2021-12-20
      • 2018-06-21
      相关资源
      最近更新 更多