【发布时间】:2016-02-16 20:23:03
【问题描述】:
我已经通过 wifi 连接了我的电脑和我的安卓设备,并在我的安卓设备上启动了 DroidCam 应用程序。
现在,如果我尝试在网络浏览器中打开 url http://192.168.100.4:8080/mjpegfeed?640x480,我可以从我的 android 手机上看到实时视频。
但如果我尝试使用 python 代码流式传输视频:
import cv2
import urllib
import numpy as np
stream=urllib.urlopen('http://192.168.100.4:8080/mjpegfeed?640x480')
bytes=''
while True:
bytes+=stream.read(1024)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
print a,b
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.CV_LOAD_IMAGE_COLOR)
cv2.imshow('i',i)
if cv2.waitKey(1) ==27:
exit(0)
代码需要一段时间,然后在控制台中打印 a=-1,b=-1。
所以基本上是这样的:
stream=urllib.urlopen('http://192.168.100.4:8080/mjpegfeed?640x480')
不工作。为什么??
【问题讨论】:
标签: android python opencv webcam http-streaming