Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.videoCapture(filename) assigning filename dynamically

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 = cam.read()

    if ret == True:
        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)        
        faces = faceDetect.detectMultiScale(gray,1.3,5);
        for(x,y,w,h) in faces :
            cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
            id,conf=rec.predict(gray[y:y+h,x:x+w])
            '''
            Few lines of code
            '''

        cv2.imshow("Face",img);
        if (cv2.waitKey(1) == ord('q')):
            break;
    else :
        print ('ret is false')
        break
cam.release()
cv2.destroyAllWindows()

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