Outils pour utilisateurs

Outils du site


streamer_des_images_opencv_avec_v4l2-loopback

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
streamer_des_images_opencv_avec_v4l2-loopback [2022/02/26 11:16] – [Profondeur d'une RealSense D455] sergestreamer_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://github.com/sergeLabo/fakewebcam
 +
 +Suppression du fond, voir
 +https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/align-depth2color.py
 +"""
 +
 import os import os
 import time import time
Ligne 123: Ligne 130:
 VIDEO = '/dev/video11' VIDEO = '/dev/video11'
  
-# Avec ou sans slider pour régler GRAY_BACKGROUND+# Avec ou sans slider pour régler CLIPPING_DISTANCE_IN_MILLIMETER
 SLIDER = 1 SLIDER = 1
- +# Réglable avec le slider 
-GRAY_BACKGROUND: Pas d'enregistrement de cette valeur +We will be removing the background of objects more than 
-si elle est modifiée par le slider, il faut le modifier ci-dessous +CLIPPING_DISTANCE_IN_MILLIMETER away 
-GRAY_BACKGROUND 153+CLIPPING_DISTANCE_IN_MILLIMETER 2000
  
  
 class MyRealSense: class MyRealSense:
  
-    def __init__(self): +    def __init__(self, video, slider, clip): 
-        global VIDEO +        self.video = video 
-        global SLIDER +        self.slider = slider 
-        global GRAY_BACKGROUND+        self.clip = clip
  
         self.width = 1280         self.width = 1280
Ligne 168: Ligne 175:
         # Getting the depth sensor's depth scale (see rs-align example for explanation)         # Getting the depth sensor's depth scale (see rs-align example for explanation)
         depth_sensor = profile.get_device().first_depth_sensor()         depth_sensor = profile.get_device().first_depth_sensor()
-        depth_scale = depth_sensor.get_depth_scale() +        self.depth_scale = depth_sensor.get_depth_scale() 
-        print("Depth Scale is: " , depth_scale) +        print("Depth Scale is: " , self.depth_scale)
-        # We will be removing the background of objects more than +
-        #  clipping_distance_in_meters meters away +
-        clipping_distance_in_meters = 1 #1 meter +
-        self.clipping_distance = clipping_distance_in_meters / depth_scale +
  
         # Affichage de la taille des images         # Affichage de la taille des images
Ligne 184: Ligne 186:
         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)
  
-        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('controls')         cv2.namedWindow('controls')
-        cv2.createTrackbar('background', 'controls', 1255+        cv2.createTrackbar('background', 'controls', 10008000
-                            self.gray_background_callback+                            self.remove_background_callback
-        cv2.setTrackbarPos('background', 'controls', gray)+        cv2.setTrackbarPos('background', 'controls', self.clip)
         cv2.namedWindow('depth', cv2.WND_PROP_FULLSCREEN)         cv2.namedWindow('depth', cv2.WND_PROP_FULLSCREEN)
  
-    def gray_background_callback(self, value): +    def remove_background_callback(self, value): 
-        global GRAY_BACKGROUND +        if value != 1000: 
-        GRAY_BACKGROUND = int(value)+            self.clip = int(value)
  
     def run(self):     def run(self):
         """Boucle infinie, quitter avec Echap dans la fenêtre OpenCV"""         """Boucle infinie, quitter avec Echap dans la fenêtre OpenCV"""
-        global GRAY_BACKGROUND 
-        global SLIDER 
  
         while self.pose_loop:         while self.pose_loop:
Ligne 221: Ligne 220:
                 continue                 continue
  
-            # Suppression du fond, voir 
-            # https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/align-depth2color.py 
             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 229: 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, depth_image))             depth_image_3d = np.dstack((depth_image, depth_image, depth_image))
-            bg_removed = np.where((depth_image_3d > self.clipping_distance) |\ +            clipping_distance = self.clip / (1000*self.depth_scale) 
-                        (depth_image_3d <= 0), GRAY_BACKGROUND, color_image)+            bg_removed = np.where((depth_image_3d > clipping_distance) |\ 
 +                        (depth_image_3d <= 0), 0, color_image)
  
             depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image,             depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image,
Ligne 237: Ligne 235:
             images = np.hstack((bg_removed, depth_colormap))             images = np.hstack((bg_removed, depth_colormap))
  
-            if SLIDER:+            if self.slider:
                 cv2.imshow('depth', images)                 cv2.imshow('depth', images)
  
Ligne 248: Ligne 246:
  
 if __name__ == '__main__': if __name__ == '__main__':
-    mrs = MyRealSense()+ 
 +    mrs = MyRealSense(VIDEO, SLIDER, CLIPPING_DISTANCE_IN_MILLIMETER)
     mrs.run()     mrs.run()
 </file> </file>
streamer_des_images_opencv_avec_v4l2-loopback.txt · Dernière modification : 2022/03/03 12:35 de serge