Ask Your Question
0

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 = 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 ?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

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
0

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

Stats

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

Seen: 2,681 times

Last updated: Aug 16 '17