Good day dear community,
I have a system that is running a Nvidia NX system with an IntelSense 3D camera. The goal is to capture the video stream with Python and OpenCV on another computer that is connected over WiFi with the system.
On my computer I can access the videostream in my browser with XXX.XXX.XX.X:8080 over mjpg-streamer. The correct http-address is: http://XXX.XXX.XX.X:8080/stream.html
Unfortunately I had zero success with different approaches. First I tried to fetch the stream directly with OpenCV:
import cv2
stream = cv2.VideoCapture('http://192.168.12.1:8080/stream.html')
while True:
ret, frame = stream.read()
cv2.imshow('Video Stream Monitor', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
stream.release()
cv2.destroyAllWindows()
This didn't work. Too easy to be true.
Next I stumbled accross this thread and thought this may be more promising because in my first example I did nothing to convert the data. I updated my code:
import cv2
import urllib
import numpy as np
# stream = cv2.VideoCapture('http://192.168.12.1:8080/stream.html')
stream = urllib.request.urlopen('http://localhost:8080/frame.mjpg')
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) & 0xFF == ord('q'):
break
stream.release()
cv2.destroyAllWindows()
And the result was an Error:
URLError: <urlopen error [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte>
Target computer denies the connection. And this is where I'm still stuck (I run Windows and it may be due to that, I will try switching to a Linux system). Although I think, that with the connection established, there will still be problems because I capture data from .html link and the code is requesting with a .mjpg ending.
Anyways, is there somebody that knows how I can get the stream from my system to my computer?
I also thought about connection the computer with a socket to the system ip and port to retrieve the data. Would that be even possible without setting up a server-client architecture on both systems? But that would be not my very first option because I already have latency because of the WiFi connection. Implementing a socket with server and client will make latency issues worse, so I'd like to retrieve the stream preferably directly.
Any help appreciated.
Everything I tried is stated with my code examples. Thus, this line is obligatory information.