【问题标题】:Ubuntu OpenCV: Program Crashing when loading video fileUbuntu OpenCV:加载视频文件时程序崩溃
【发布时间】:2018-01-20 03:50:43
【问题描述】:

我正在尝试在 python 中使用 opencv 加载视频文件。程序崩溃并返回:

$ python bg_reduction.py 分段错误(核心转储)

在浏览论坛数小时后,我开始意识到问题可能出在我构建的 opencv 上。我是一名新手程序员和 linux 用户,所以无论如何我发现的大部分内容都超出了我的想象。

这是我的程序的要点 - 从网络摄像头流式传输视频时有效,从文件加载时失败。

cap = cv2.VideoCapture('SuccessPrint.mp4')                                                               
fgbg = cv2.createBackgroundSubtractorMOG2()                                                                                                         

while (cap.isOpened()):                                                                                                                             
    try:                                                                                                                                            
        ret, frame = cap.read()                                                                                                                     
    except cv2.error:                                                                                                                               
        cap.release()                                                                                                                               
        cv2.destroyAllWindows()                                                                                                                     

    k = cv2.waitKey(30) & 0xFF                                                                                                                      
    if k == 27:                                                                                                                                     
        break                                                                                                                                       

cap.release()                                                                                                                                       
cv2.destroyAllWindows()

这里是返回的编解码器信息:

$ffmpeg -i SuccessPrint.mp4

Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 557 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)

最后是来自核心的信息:

$gdb bg_reduction.py core

返回(我已经删除了路径):

    /bg_reduction2.py": not in executable format: File format not recognized
[New LWP 12398]
[New LWP 12401]
[New LWP 12399]
[New LWP 12400]
Core was generated by `python bg_reduction2.py'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007fe3c7364fd1 in ?? ()
[Current thread is 1 (LWP 12398)]
(gdb)

任何建议都会令人难以置信。提前致谢!

【问题讨论】:

    标签: python opencv ubuntu video crash


    【解决方案1】:

    更新:已解决

    问题是最初的构建:

    linux/videodev.h not found 
    

    必须运行这些代码:

    sudo apt-get install libv4l-dev
    cd /usr/include/linux
    sudo ln -s ../libv4l1-videodev.h videodev.h
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多