Created
April 12, 2021 17:21
-
-
Save alduxvm/335286a499eb82fe20a0ab75a9dda6a8 to your computer and use it in GitHub Desktop.
Sony QX-10 open stream with python3 and opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Before using this script: manually connect to the Wi-Fi of the camera and make sure you have the 10.0.1.1 address in your machine | |
""" | |
import cv2 | |
import urllib.request | |
import numpy as np | |
stream = urllib.request.urlopen('http://10.0.0.1:60152/liveview.JPG?%211234%21http%2dget%3a%2a%3aimage%2fjpeg%3a%2a%21%21%21%21%21') | |
buf = b'' | |
c = 0 | |
while True: | |
nextPart = stream.read(1024) | |
jpegStart = nextPart.find(b'\xFF\xD8\xFF') | |
jpegEnd = nextPart.find(b'\xFF\xD9') | |
if jpegEnd != -1: | |
c += 1 | |
buf += nextPart[:jpegEnd + 2] | |
try: | |
i = cv2.imdecode(np.fromstring(buf, dtype=np.uint8), cv2.IMREAD_COLOR) | |
cv2.imshow('Live view', i) | |
if cv2.waitKey(1) == 27: | |
exit(0) | |
except Exception as error: | |
print(error) | |
if jpegStart != -1: | |
buf = nextPart[jpegStart:] | |
else: | |
buf += nextPart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment