streamer_des_images_opencv_avec_v4l2-loopback
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
streamer_des_images_opencv_avec_v4l2-loopback [2022/02/26 11:17] – [Profondeur d'une RealSense D455] serge | streamer_des_images_opencv_avec_v4l2-loopback [2022/03/03 12:35] (Version actuelle) – [Profondeur d'une RealSense D455] serge | ||
---|---|---|---|
Ligne 112: | Ligne 112: | ||
<file python sender_rs_depth.py> | <file python sender_rs_depth.py> | ||
+ | """ | ||
+ | Voir https:// | ||
+ | |||
+ | Suppression du fond, voir | ||
+ | https:// | ||
+ | """ | ||
+ | |||
import os | import os | ||
import time | import time | ||
Ligne 118: | Ligne 125: | ||
import numpy as np | import numpy as np | ||
import pyrealsense2 as rs | import pyrealsense2 as rs | ||
+ | |||
# Le faux device | # Le faux device | ||
VIDEO = '/ | VIDEO = '/ | ||
- | # Avec ou sans slider pour régler | + | |
+ | # Avec ou sans slider pour régler | ||
SLIDER = 1 | SLIDER = 1 | ||
- | # GRAY_BACKGROUND: | + | # Réglable avec le slider |
- | # si elle est modifiée par le slider, il faut le modifier ci-dessous | + | # We will be removing the background of objects more than |
- | GRAY_BACKGROUND | + | # CLIPPING_DISTANCE_IN_MILLIMETER away |
+ | CLIPPING_DISTANCE_IN_MILLIMETER | ||
class MyRealSense: | class MyRealSense: | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | | ||
self.width = 1280 | self.width = 1280 | ||
Ligne 163: | Ligne 175: | ||
# Getting the depth sensor' | # Getting the depth sensor' | ||
depth_sensor = profile.get_device().first_depth_sensor() | depth_sensor = profile.get_device().first_depth_sensor() | ||
- | depth_scale = depth_sensor.get_depth_scale() | + | |
- | print(" | + | print(" |
- | # We will be removing the background of objects more than | + | |
- | # clipping_distance_in_meters meters away | + | |
- | clipping_distance_in_meters = 1 #1 meter | + | |
- | | + | |
# Affichage de la taille des images | # Affichage de la taille des images | ||
Ligne 179: | Ligne 186: | ||
self.camera = pyfakewebcam.FakeWebcam(VIDEO, | self.camera = pyfakewebcam.FakeWebcam(VIDEO, | ||
- | if SLIDER: | + | if self.slider: |
- | self.create_slider(GRAY_BACKGROUND) | + | self.create_slider() |
- | def create_slider(self, gray): | + | def create_slider(self): |
- | # # global GRAY_BACKGROUND | + | |
cv2.namedWindow(' | cv2.namedWindow(' | ||
- | cv2.createTrackbar(' | + | cv2.createTrackbar(' |
- | self.gray_background_callback) | + | self.remove_background_callback) |
- | cv2.setTrackbarPos(' | + | cv2.setTrackbarPos(' |
cv2.namedWindow(' | cv2.namedWindow(' | ||
- | def gray_background_callback(self, value): | + | def remove_background_callback(self, value): |
- | | + | |
- | | + | |
def run(self): | def run(self): | ||
""" | """ | ||
- | global GRAY_BACKGROUND | + | |
- | global SLIDER | + | |
while self.pose_loop: | while self.pose_loop: | ||
+ | |||
# Get frameset of color and depth | # Get frameset of color and depth | ||
frames = self.pipeline.wait_for_frames() | frames = self.pipeline.wait_for_frames() | ||
Ligne 214: | Ligne 220: | ||
continue | continue | ||
- | # Suppression du fond, voir | ||
- | # https:// | ||
depth_image = np.asanyarray(aligned_depth_frame.get_data()) | depth_image = np.asanyarray(aligned_depth_frame.get_data()) | ||
color_image = np.asanyarray(color_frame.get_data()) | color_image = np.asanyarray(color_frame.get_data()) | ||
Ligne 222: | Ligne 226: | ||
# depth image is 1 channel, color is 3 channels | # depth image is 1 channel, color is 3 channels | ||
depth_image_3d = np.dstack((depth_image, | depth_image_3d = np.dstack((depth_image, | ||
- | bg_removed = np.where((depth_image_3d > self.clipping_distance) |\ | + | |
- | (depth_image_3d <= 0), GRAY_BACKGROUND, color_image) | + | |
+ | (depth_image_3d <= 0), 0, color_image) | ||
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, | depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, | ||
Ligne 230: | Ligne 235: | ||
images = np.hstack((bg_removed, | images = np.hstack((bg_removed, | ||
- | if SLIDER: | + | if self.slider: |
cv2.imshow(' | cv2.imshow(' | ||
+ | |||
self.camera.schedule_frame(bg_removed) | self.camera.schedule_frame(bg_removed) | ||
if cv2.waitKey(1) == 27: | if cv2.waitKey(1) == 27: | ||
break | break | ||
+ | |||
+ | |||
if __name__ == ' | if __name__ == ' | ||
- | | + | |
+ | | ||
mrs.run() | mrs.run() | ||
</ | </ |
streamer_des_images_opencv_avec_v4l2-loopback.txt · Dernière modification : 2022/03/03 12:35 de serge