Ask Your Question

Arshad's profile - activity

2018-05-18 12:46:13 -0600 received badge  Famous Question (source)
2018-01-13 06:26:17 -0600 received badge  Notable Question (source)
2017-10-16 13:50:14 -0600 received badge  Popular Question (source)
2017-05-03 23:54:20 -0600 asked a question 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 ?

2017-05-03 20:17:52 -0600 answered a question cap.read() returns false

Refer to answer by osama abbas here (http://stackoverflow.com/questions/35...)

It worked for me after following those steps

2017-04-21 19:23:53 -0600 received badge  Enthusiast
2017-04-16 20:58:20 -0600 commented answer how to use IP camera in place of webcam in python ?

Code :

cam =cv2.VideoCapture('http://192.168.1.4:8080/video')
    while(True):
         ret,img = cam.read();
         gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
          ...

Error :

        Traceback (most recent call last):
          File "C:\Face rocog project\Face recog
sqllite\datasetCreator.py", line 33,
in <module>
            gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        error: ..\..\..\..\opencv\modules\imgproc\src\color.cpp:3739:
error: (-215) scn == 3 || scn == 4
    in function cv::cvtColor

It is working fine with VideoCapture(0) but having this error with ip cam

2017-04-16 11:04:51 -0600 asked a question how to use IP camera in place of webcam in python ?

I have been using this logic all the while. I was using standard webcam with cv2 (version 2.4.13)

cam = cv2.VideoCapture(0)
while(True):
    ret,img = cam.read()

But i want to use IP camera in place of webcam. give a lead how to get around with IP camera in openCV+Python