Ask Your Question

cv2.videoCapture(filename) assigning filename dynamically

asked 2017-05-03 23:54:20 -0600

Arshad gravatar image

I am trying to access filename dynamically from user and then pass it to videoCapture(filename) and then process it.

code :

import cv2
import numpy as np
import os
import sqlite3
import pickle
from PIL import Image
import sys

faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
rec = cv2.createLBPHFaceRecognizer();

Dynamically accessing the fileName

Error seems to be here in the following couple of codes
Note: i am assigning file_name as <"test.mp4">
file_name = raw_input("Enter file name: ")
print file_name

cam = cv2.VideoCapture(file_name)

while cam.isOpened():
    ret,img =

    if ret == True:
        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)        
        faces = faceDetect.detectMultiScale(gray,1.3,5);
        for(x,y,w,h) in faces :
            Few lines of code

        if (cv2.waitKey(1) == ord('q')):
    else :
        print ('ret is false')

it show no error but it dows not execute the while(cam.isOpened): loop. am i missing something ?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2017-05-05 16:17:31 -0600

electron gravatar image

1) Check if file exists. Try to use absolute path there, and use '/' instead of '\' if you are on windows

2) According to docs:

Sometimes, it is a headache to work with Video Capture mostly due to wrong installation of ffmpeg/gstreamer.

It can be an issue too

edit flag offensive delete link more

answered 2017-08-16 21:01:27 -0600

supra56 gravatar image
file_name = input("Enter file name: ")
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-05-03 23:54:20 -0600

Seen: 2,337 times

Last updated: Aug 16 '17