Stream depth camera (Intel D455) with OpenCV

Hello,

I’m trying to stream a depth video from Intel D455 Depth Camera via http to get it back in another machine.

I wanted to use cv2.VideoCapture(Input_Depth_Flux).

If in print(Input_Depth_Flux) i will get a matrix with every value for each pixels (which correspond to the distance), so i suppose i have to encode this or something but i’m a but lost how to do this…

Could you help me to get on the way

Here is the script I expected to adapt to stream depth, and when i put the depth_frame in argument you can see the error message i get:

I’m not advanced in python and opencv I saw some tutorial on this library but still not all clear, So feel free to explain even if it seems stupid for you :slight_smile:

Here is the script I’m trying to inspire from which display depth_stream via cv2.imshow

I precise it work perfectly and display the depth video

please post code, not images of it, thank you.

Well here is the code I use to get the image:


from realsense_camera import *
import cv2
import os

rs = RealsenseCamera()

while True:
    ret,bgr_frame, depth_frame = rs.get_frame_stream()
    distance = depth_frame[100,100]
    print(depth_frame)
    cv2.imshow("Depth Frame", depth_frame)
    key = cv2.waitKey(1)
    if key == 27:
            break

You can get realsense_camera module following this link :

The second code i try to adapt to stream depth is:

# Part 01 using opencv access webcam and transmit the video in HTML
import cv2
import pyshine as ps #  pip3 install pyshine==0.0.9
from realsense_camera import *

HTML="""
<html>

<body>
<center><img src="stream.mjpg" width='640' height='480' autoplay playsinline></center>
</body>
</html>
"""

StreamProps = ps.StreamProps
StreamProps.set_Page(StreamProps,HTML)
address = ('10.112.45.31',9000) # Enter your IP address 

rs = RealsenseCamera()
    


while True:


    
    StreamProps.set_Mode(StreamProps,'cv2')

    ret,bgr_frame, depth_frame = rs.get_frame_stream()
    #distance = depth_frame[100,100]
    #print(distance)
    #cv2.imshow("Depth Frame", depth_frame)
    
    print(depth_frame)
    Input_video =  depth_frame
    capture = cv2.VideoCapture(Input_video)
    print(capture.read())
    StreamProps.set_Capture(StreamProps,capture)
    StreamProps.set_Quality(StreamProps,90)
    server = ps.Streamer(address,StreamProps)
    print('Server started at','http://'+address[0]+':'+str(address[1]))
    server.serve_forever()

    key = cv2.waitKey(1)
    
    
    if key == 27:
            break

you’re using realsense_camera and something called pyshine (unmaintained, nobody uses it, doesn’t even have a working github repo). neither has anything to do with OpenCV.

your use of VideoCapture is nonsensical. you already have the depth data from the realsense library.

this is just a basic programming problem you’re asking about. your use of loops indicates that you have no idea what your code does. this forum is not for general programming questions.

thanks for helping it’s a bit more clear

effectively I don’t understand all my code I started python 3 weeks ago and I’m trying to improve by projects

Thanks for your encouragement