2017-08-07 18 views
3

Impossible d'accéder au flux vidéo. Quelqu'un peut-il s'il vous plaît m'aider à obtenir le flux vidéo. J'ai cherché dans google pour la solution et poster une autre question dans le débordement de pile mais malheureusement rien ne peut pas résoudre le problème.Accéder à la caméra IP avec OpenCV

import cv2 
cap = cv2.VideoCapture() 
cap.open('http://192.168.4.133:80/videostream.cgi?user=admin&pwd=admin') 
while(cap.isOpened()): 
    ret, frame = cap.read() 
    cv2.imshow('frame', frame) 
    if cv2.waitKey(1) & 0xFF == ord('q'): 
     break 
cap.release() 
cv2.destroyAllWindows() 

Répondre

1

Vous pouvez utiliser urllib pour lire des images à partir d'un flux vidéo.

import cv2 
import urllib 
import numpy as np 

stream = urllib.urlopen('http://192.168.100.128:5000/video_feed') 
bytes = '' 
while True: 
    bytes += stream.read(1024) 
    a = bytes.find(b'\xff\xd8') 
    b = bytes.find(b'\xff\xd9') 
    if a != -1 and b != -1: 
     jpg = bytes[a:b+2] 
     bytes = bytes[b+2:] 
     img = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR) 
     cv2.imshow('Video', img) 
     if cv2.waitKey(1) == 27: 
      exit(0) 

Cochez cette option si vous voulez diffuser la vidéo de la webcam de votre PC. https://github.com/shehzi-khan/video-streaming

3

Merci. Peut être, maintenant urlopen n'est pas sous utllib. Il est sous urllib.request.urlopen.I utilise ce code:

import cv2 
from urllib.request import urlopen 
import numpy as np 

stream = urlopen('http://192.168.4.133:80/video_feed') 
bytes = '' 
while True: 
    bytes += stream.read(1024) 
    a = bytes.find(b'\xff\xd8') 
    b = bytes.find(b'\xff\xd9') 
    if a != -1 and b != -1: 
     jpg = bytes[a:b+2] 
     bytes = bytes[b+2:] 
     img = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR) 
     cv2.imshow('Video', img) 
     if cv2.waitKey(1) == 27: 
      exit(0)