VideoCapture无法打开视频文件

时间:2017-06-10 17:01:46

标签: opencv opencv3.2

我正试图从视频文件中逐帧读取图像。视频文件放在当前目录中。试图提供视频文件的绝对路径仍然 cat.isOpened()函数调用返回false。此设置在ubuntu 16.04机器上,使用pip3安装opencv。

即使使用这些标志 cv2.CAP_FFMPEG,cv2.CAP_IMAGES和cv2.CAP_DSHOW 作为VideoCapture()构造函数的第二个参数,isOPened()也返回false。

有没有办法找出导致错误的原因?

import cv2

cap = cv2.VideoCapture('Megamind.avi')
if not cap.isOpened():
    print("unable to open") # prints this 

编辑5: 成功打开文件后,下列strace是否出现意外情况。

$ strace python3 face_detect.py

......
......
open("Megamind.avi", O_RDONLY)          = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=1189270, ...}) = 0
read(3, "RIFF\216%\22\0AVI LISTr\"\0\0hdrlavih8\0\0\0"..., 4096) = 4096
lseek(3, 0, SEEK_CUR)                   = 4096
lseek(3, 0, SEEK_CUR)                   = 4096
lseek(3, 0, SEEK_CUR)                   = 4096
lseek(3, 0, SEEK_SET)                   = 0
read(3, "RIFF\216%\22\0AVI LISTr\"\0\0hdrlavih8\0\0\0"..., 4096) = 4096
lseek(3, 4096, SEEK_SET)                = 4096
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
lseek(3, 1187840, SEEK_SET)             = 1187840
read(3, "\16\0\351\3\0\00000dc\0\0\0\0F\331\16\0A\22\0\00001wb\20\0\0\0\220\353"..., 4096) = 1430
read(3, "", 4096)                       = 0
close(3)                                = 0
write(1, "unable to open\n", 15unable to open
)        = 15
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f33fcc27390}, {0x63df70, [], SA_RESTORER, 0x7f33fcc27390}, 8) = 0
futex(0x7f33f92f62bc, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f33f92f62b8, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x7f33f92f6290, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f33f92f633c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f33f92f6338, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x7f33f92f6310, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f33f92f63bc, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f33f92f63b8, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x7f33f92f6390, FUTEX_WAKE_PRIVATE, 1) = 1
munmap(0x7f33f42b8000, 33554432)        = 0
munmap(0x7f33f1ab7000, 33554432)        = 0
munmap(0x7f33ef276000, 33554432)        = 0
exit_group(0)                           = ?
+++ exited with 0 +++

1 个答案:

答案 0 :(得分:0)

发现问题。问题是没有安装opencv。 pip安装python绑定到opencv但不安装c ++ opencv,也不报告它。

通过安装ppa https://launchpad.net/~lkoppel/+archive/ubuntu/opencv

解决