Ask Your Question
0

Videocapture in opencv 3.0.0 is not reading the video

asked 2016-10-12 12:41:50 -0600

pythonuser gravatar image

updated 2016-10-12 13:09:24 -0600

Hi, I am using opencv 3.0.0 on ubuntu 16.04 with python 2.7.12 in virtual environment. When I am writing the following program,

import cv2
import os.path
import numpy as np

print os.path.isfile("/home/user/.VIRTUALENVS/cv/lib/python2.7/site-packages/ped1.avi")
cap = cv2.VideoCapture("/home/user/.VIRTUALENVS/cv/lib/python2.7/site-packages/ped1.avi")

ret, frame1 = cap.read()
print ret 
prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)

then output that I am getting is as follows:

True
False

Traceback (most recent call last):
File "/home/varun/.VIRTUALENVS/cv/lib/python2.7/site-packages/check.py", line 10, in <module>
prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
error: /home/varun/opencv/modules/imgproc/src/color.cpp:7564: error: (-215) scn == 3 || scn == 4 in function cvtColor

The false statement is showing that program is not reading the file. File does exist there. I tried solutions given here and here but still it is not working. Please help. Thanks in advance.

edit retag flag offensive close merge delete

Comments

If I am lacking with some information kindly let me know. Please answer the above question.

pythonuser gravatar imagepythonuser ( 2016-10-13 04:47:57 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-10-12 13:15:40 -0600

x10s gravatar image

You should check if the video you're trying to read is opened before trying to read a frame and convert it to grayscale.

  cap = cv2.VideoCapture("/home/user/.VIRTUALENVS/cv/lib/python2.7/site-packages/ped1.avi")
  while(cap.isOpened()):
    ret, frame1 = cap.read()
    if ret:
      prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
edit flag offensive delete link more

Comments

I checked. This is the problem. Videocapture is not opening the files. I also tried your method but as expected, program executed without going inside while loop.

pythonuser gravatar imagepythonuser ( 2016-10-13 02:15:25 -0600 )edit

Does your program have read permissions on the video file?

x10s gravatar imagex10s ( 2016-10-13 09:19:34 -0600 )edit

I did following: os.access("/home/user/.VIRTUALENVS/cv/lib/python2.7/site-packages/ped1.avi", os.R_OK) then it is returning; True. Is this different from what you are asking?

pythonuser gravatar imagepythonuser ( 2016-10-13 10:21:40 -0600 )edit

No, that's what I meant. The only other thing I can think of are unmet dependencies like ffmpeg?

x10s gravatar imagex10s ( 2016-10-13 10:55:46 -0600 )edit

As I am using opencv 3.0.0 so I copied the files "opencv_ffmpeg.dll" and paste it into the python's folder i.e. "/home/user/.VIRTUALENVS/cv/lib/python2.7" with changed name "opencv_ffmpeg3.dll". I also copied the file "opencv_ffmpeg_64.dll" into same folder as "opencv_ffmpeg3_64.dll" but even then it is not working.

pythonuser gravatar imagepythonuser ( 2016-10-13 11:14:05 -0600 )edit

dll? Your original question says that you're on a linux machine and your file paths indicate the same. Have you followed the correct compile and install procedure for opencv on linux?

x10s gravatar imagex10s ( 2016-10-13 22:54:01 -0600 )edit
0

answered 2016-10-30 02:08:02 -0600

xiaoerlaigeid gravatar image

i think virtual machine can't get the permission to open your camera. I have the same problem.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-10-12 12:41:50 -0600

Seen: 1,996 times

Last updated: Oct 30 '16