openCV online Camera [closed]

asked 2018-06-01 13:05:06 -0600

WaleedJubeh gravatar image

Hello.

I'm trying to make face recognition and i did it in my laptop camera . Now i have cameras connected to the DVR . So i need to connect to them by my app to see my cameras even if i connect to another Network so how can i modify my code to make "VideoCapture" get my camera ?

import cv2
import numpy as np
import os
import pickle
face_cascade=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

recognizer=cv2.face.LBPHFaceRecognizer_create()
recognizer.read("E:\\trained.yml");
recognizer.setThreshold(90);

cap=cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
while(True):

    ret,frame=cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('gray?',gray)

    faces = face_cascade.detectMultiScale(frame, 1.3, 5)
    for (x,y,w,h) in faces:
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = frame[y:y+h, x:x+w]
        idLablel,conf=recognizer.predict(gray[y:y+h,x:x+w])
        cv2.putText(frame,str(idLablel),(x,y+h),font,4,(255,255,255));

        cv2.putText(frame,str(conf),(x+w,y+h),font,4,(255,255,255));
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break;
cap.release()    
cv2.waitKey(0)
cv2.destroyAllWindows()
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-20 03:26:44.904726

Comments

I think you might only need to change the 0 in cap=cv2.VideoCapture(0) The the ip of your "online camera" or to a streaming link that your camera might give you... For example, I'm using an ONVIF conformant camera and I'm getting a RTSP link from it. So, I had to use cap = cv2.VideoCapture("rtsp://user:[email protected]/stream0")

tirolock gravatar imagetirolock ( 2018-06-01 14:03:05 -0600 )edit

so i need to get RTSP links to run them.. this will work even network changed?

WaleedJubeh gravatar imageWaleedJubeh ( 2018-06-01 15:15:56 -0600 )edit

its work put ur answer to submit it

WaleedJubeh gravatar imageWaleedJubeh ( 2018-06-04 18:06:19 -0600 )edit