Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
realsense testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljhan01 committed Dec 22, 2022
1 parent 8109cd0 commit 747e3f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Binary file added .opencv_viewer_example.py.swp
Binary file not shown.
Empty file added object_detection.py
Empty file.
Binary file added object_detection/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
30 changes: 15 additions & 15 deletions opencv_viewer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Open CV and Numpy integration ##
###############################################

import pyrealsense2 as rs
import pyrealsense2.pyrealsense2 as rs
import numpy as np
import cv2

Expand Down Expand Up @@ -43,34 +43,34 @@

# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
#depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
if not depth_frame or not color_frame:
if not color_frame:
continue

# Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
#depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())

# Apply colormap on depth image (image must be converted to 8-bit per pixel first)
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
#depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

depth_colormap_dim = depth_colormap.shape
color_colormap_dim = color_image.shape
#depth_colormap_dim = depth_colormap.shape
#color_colormap_dim = color_image.shape

# If depth and color resolutions are different, resize color image to match depth image for display
if depth_colormap_dim != color_colormap_dim:
resized_color_image = cv2.resize(color_image, dsize=(depth_colormap_dim[1], depth_colormap_dim[0]), interpolation=cv2.INTER_AREA)
images = np.hstack((resized_color_image, depth_colormap))
else:
images = np.hstack((color_image, depth_colormap))
## If depth and color resolutions are different, resize color image to match depth image for display
#if depth_colormap_dim != color_colormap_dim:
# resized_color_image = cv2.resize(color_image, dsize=(depth_colormap_dim[1], depth_colormap_dim[0]), interpolation=cv2.INTER_AREA)
# images = np.hstack((resized_color_image, depth_colormap))
#else:
# images = np.hstack((color_image, depth_colormap))

# Show images
cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
cv2.imshow('RealSense', images)
cv2.imshow('RealSense', color_image)
cv2.waitKey(1)

finally:

# Stop streaming
pipeline.stop()
pipeline.stop()

0 comments on commit 747e3f0

Please sign in to comment.