Skip to content

Instantly share code, notes, and snippets.

@youqingkui
Last active January 31, 2018 01:31
Show Gist options
  • Select an option

  • Save youqingkui/b4f88e3b607ed5e3239e645ef0a4dfac to your computer and use it in GitHub Desktop.

Select an option

Save youqingkui/b4f88e3b607ed5e3239e645ef0a4dfac to your computer and use it in GitHub Desktop.

Revisions

  1. youqingkui renamed this gist Jan 31, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. youqingkui created this gist Jan 31, 2018.
    39 changes: 39 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import cv2
    import urllib
    import numpy as np

    stream=urllib.urlopen('http://192.168.31.249:8080/video')
    bytes=''
    while True:
    bytes+=stream.read(1024)
    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.CV_LOAD_IMAGE_COLOR)
    cv2.imshow('i',i)
    if cv2.waitKey(1) ==27:
    exit(0)


    import cv2
    import requests
    import numpy as np

    r = requests.get('http://192.168.31.249:8080/video', stream=True)
    if(r.status_code == 200):
    bytes = bytes()
    for chunk in r.iter_content(chunk_size=1024):
    bytes += chunk
    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:]
    i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
    cv2.imshow('i', i)
    if cv2.waitKey(1) == 27:
    exit(0)
    else:
    print("Received unexpected status code {}".format(r.status_code))