1 year ago
#284873
Bilal
How to draw the perimeter of the depth FOV of Intel Realsense camera
I have Intel Realsense L515 camera, and I want to align the depth FOV perfectly to fit a workspace before fixing the camera position, hence I want to draw a rectangle around the FOV.
My preliminary idea was to get the distance of the center, and draw a rectangle knowing the angles of the FOV a=70, B=55
.
Then I realized that the FOV might not be a rectangle due to the variance in the depth among the center and the perimeter of the FOV region, so I decided to use a slider to draw the rectangle according to the distance from the slider and suppress the depth values that don't belong to the FOV of the chosen distance.
Can you please tell me how can I do it correctly? thanks in advance.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cv2
import numpy as np
from math import tan, radians
import pyrealsense2 as rs
"""
# L515 FOV
Ref: https://dev.intelrealsense.com/docs/lidar-camera-l515-datasheet
"""
def fov_bbox(center, depth_frame):
"""
L515 FOV Rect
"""
alpha = 70 # in degrees
beta = 55 # in degrees
cx, cy = center
ddist = depth_frame.get_distance(cx, cy)
ddist = ddist*1000
x_dist = int(ddist * tan(radians(alpha)))
y_dist = int(ddist * tan(radians(beta )))
"""
1--->2
|
V
4<---3
"""
bbox = [(cy - y_dist, cx - x_dist), (cy - y_dist, cx + x_dist), (cy + y_dist, cx + x_dist), (cy + y_dist, cx - x_dist)]
return bbox
# def callback(x):
# pass
# cv2.createTrackbar('distance', 'depth', ddist, 100, callback)
cv2.namedWindow('depth', cv2.WINDOW_NORMAL)
res = [(1280, 720), (640, 480)]
resolution = res[1]
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, resolution[0], resolution[1], rs.format.z16, 30)
pipeline.start(config)
profile = pipeline.get_active_profile()
sensor = profile.get_device().query_sensors()[0] # 0 for depth, 1 for rgb
sensor.set_option(rs.option.laser_power, 80)
try:
while (True):
# Capture depth
# Wait for depth frames:
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
if not depth_frame:
continue
# Convert images to numpy arrays
depth_array = np.asanyarray(depth_frame.get_data())
# Read distance form the Slider
# ddist = cv2.getTrackbarPos('distance','depth')
# Segment Depth according to the distance
# depth_array[depth_array>ddist] = 0
# Parse the FOV with depth >= slider value
center = (depth_array.shape[1]//2, depth_array.shape[0]//2)
start_point, _, end_point, _ = fov_bbox(center, depth_frame)
print(center, start_point, end_point)
color = 255
thickness = 2
depth_array = cv2.rectangle(depth_array, start_point, end_point, color, thickness)
cv2.imshow("depth", depth_array)
if(cv2.waitKey(1) & 0xFF == ord('q')):
cv2.destroyAllWindows()
break
finally:
# Stop streaming
pipeline.stop()
python
opencv
computer-vision
depth
realsense
0 Answers
Your Answer