Robotics StackExchange | Archived questions

get depth image from zed camera

i used this code to get depth image but i don't knew what's missing i got just a gray window :

#! /usr/bin/env python
import cv2
import numpy as np
cap = cv2.VideoCapture(1)

if (cap.isOpened() == False):
    print("Unable to read camera feed")

frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
out = cv2.VideoWriter('outpy.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 10, (frame_width, frame_height))


while (True):
    ret, frame = cap.read()
    vidL = frame[:, 0:1280] # left camera
    vidR = frame[:, 1280:2560] # right camera

     vL=cv2.cvtColor(vidL, cv2.COLOR_BGR2GRAY)
     vR=cv2.cvtColor(vidR, cv2.COLOR_BGR2GRAY)



     cv2.imshow('frame', frame)
     stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)
     disparity = stereo.compute(vR,vL)
     cv2.imshow('depth',disparity)
     if cv2.waitKey(1) & 0xFF == ord('q'):
      break



cap.release()
out.release()

# Closes all the frames
cv2.destroyAllWindows()

Asked by abdelkrim on 2018-04-10 08:24:09 UTC

Comments

Answers

You might want Zed to do the computing for you, and supply the depth image. It will figure the disparity itself. /zed/depth/depth_registered Are you using zed-ros-wrapper?

Asked by Rodolfo8 on 2018-04-10 15:05:51 UTC

Comments

i'am using zed-ros-wrapper but i wanna work with python to do some demonstration after continue in ros

Asked by abdelkrim on 2018-04-11 07:01:20 UTC