Je travaille sur l'utilisation de Python 3 pour prendre un flux de caméra web IP et l'afficher sur mon ordinateur. Le code suivant ne fonctionne que dans python 2,7Caméra IP Python 3 Erreur
import cv2
import urllib
import numpy as np
stream=urllib.urlopen('http://192.168.0.90/mjpg/video.mjpg')
bytes=''
while True:
bytes+=stream.read(16384)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes= bytes[b+2:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR)
cv2.imshow('i',i)
if cv2.waitKey(1) ==27:
exit(0)
Cependant quand j'essaie sur Python 3, je suis l'erreur suivante
stream=urllib.urlopen(' http://192.168.0.90/mjpg/video.mjpg ') AttributeError: 'module' object has no attribute 'urlopen'
Y at-il correctif pour cela? J'ai essayé de faire mon propre tampon, mais il n'y a pas beaucoup d'informations là-bas sur ce genre de choses
peut-être que vous pourriez donner à ce essayer la prochaine fois https: //docs.python .org/2/library/2to3.html il traduit automatiquement py2 en py3, semble couvrir urllib – titus