Save Zed Video with custom Text and Rectangle

Hello,
I need to save the text and rectangle with video frames.
However, when I run the following code, It only records the file and save it.
It does not save the rectangle and text with video frames.
How can I do save the video with text and rectangle?

NOTE:
I have also tried to use opecv videoWriter function but it fails to save.
result = cv2.VideoWriter(‘saveFile_WRITE.avi’,
cv2.VideoWriter_fourcc(*‘MJPG’),
10, (640, 480))
Therefore, I used camera.enable_recording because it saves files. But it fails to save the video with text and rectangle.

Code

filepath = “saveFile.svo”
record_param = sl.RecordingParameters(filepath)
vid = camera.enable_recording(record_param)

while True:
if camera.grab(runtime_params) == sl.ERROR_CODE.SUCCESS:
camera.retrieve_image(image, sl.VIEW.LEFT) # Retrieve left image
camera.retrieve_image(depth_map, sl.VIEW.DEPTH) # Retrieve depth

    numpy_image = image.get_data()
    numpy_depth_map = depth_map.get_data()

    # Using cv2.putText()
    new_image = cv2.putText(
        img=numpy_image,
        text="Save this Text with Video frame",
        org=(200, 200),
        fontFace=cv2.FONT_HERSHEY_DUPLEX,
        fontScale=3.0,
        color=(125, 246, 55),
        thickness=3
    )
    cv2.rectangle(numpy_image, (70, 70), (270, 575), (227, 207, 87), 2)

    cv2.imshow('image', numpy_image)
    cv2.imshow('DEPTH', numpy_depth_map)


    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
        camera.disable_recording()

Hi,
Our own SVO file format only record raw data directly from the camera. If you want to add custom data you can use the cvCapture class.

However, in case of using cvCapture, the problem is
How can I access zed depth image when I use

cap = cv2.VideoCapture(0)

instead of

zed = sl.Camera() 

Using cv2.VideoCapture(0) gives only RGB image frame, not depth frame information.

        # Get a new frame from camera
        retval, frame = cap.read()

Therefore, when I use the following code after using cv2.VideoCapture(0)

    while True :
              # Get a new frame from camera
              retval, frame = cap.read()
              camera.retrieve_image(depth_map, sl.VIEW.DEPTH)  # Retrieve depth
              depth_ocv = depth_map.get_data()
              print(depth_ocv[int(len(depth_ocv) / 2)][int(len(depth_ocv[0]) / 2)])

It shows a black image. It does not show depth image.
So, How depth video image of Zed Camera can be obtained using VideoCapture(0)?

I also searched on github zed python-opoen examples. But I could not find its example example.
In Zed Opencv-python examples, they are getting only left and right image frame with but not the depth image with cvCapture.

So, need help.

Thank You

Hi,

I think that using cv.VideoWriter was the write approach. With that you can save any matrix. So you can retrieve the depth, add some opencv shapes on it, and save it.

result = cv2.VideoWriter('filename.avi', 
                         cv2.VideoWriter_fourcc(*'MJPG'),
                         10, size)
    
while(True):
    # grab the camera
    # retrieve the depth image into a matrix named 'depth'
    # modify this matrix
  

  
    # Write the frame into the
    # file 'filename.avi'
    result.write(depth)
  
    # Display the frame
    # saved in the file
    cv2.imshow('Frame', frame)
  
    # Press S on keyboard 
    # to stop the process
    if cv2.waitKey(1) & 0xFF == ord('s'):
        break