0
votes

I am trying to read image frame by frame from the video file. The video file is placed in the current directory. Tried to provide the absolute path of the video file still cat.isOpened() function call returns false. This setup is on ubuntu 16.04 machine, installed opencv using pip3.

The isOPened() returns false even with these flags cv2.CAP_FFMPEG, cv2.CAP_IMAGES and cv2.CAP_DSHOW as the second argument to the VideoCapture() constructor.

Is there any way to find out what caused the error ?

import cv2

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

EDIT 5: Is there something unexpected with the following strace after opening the file successfully.

$ 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

1 Answers

0
votes

Found the problem. The issue is opencv was not installed. pip installs python binding to opencv but not the c++ opencv, also it does not report it.

Solved by installing ppa https://launchpad.net/~lkoppel/+archive/ubuntu/opencv