Search code examples
androidpythonopencvwebcamhttp-streaming

unable to http stream from ip android cam


I have connected my pc and my android device over wifi and started the DroidCam app on my android device.
Now if i try to open the url http://192.168.100.4:8080/mjpegfeed?640x480 in web browser, i am able to see the live video from my android mobile.
But if i try to stream video using python code:

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)   

the code takes a while and then just prints a=-1,b=-1 in the console.
so basically the line:

stream=urllib.urlopen('http://192.168.100.4:8080/mjpegfeed?640x480')

is not working. WHY??


Solution

  • Well i just restarted the computer and it starts working!