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:15] – [Profondeur d'une OAK-D Lite] 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>
- 
 """ """
-Créer un device /dev/video11 +Voir https://github.com/sergeLabo/fakewebcam
-Commande non persistante, c'est perdu au reboot+
  
-sudo modprobe v4l2loopback video_nr=11 +Suppression du fondvoir 
- +https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/align-depth2color.py
-Necéssite pyrealsense2 +
- +
-Sans VirtualEnv +
- +
-    python3 -m pip install numpy opencv-python pyfakewebcam pyrealsense2 +
- +
-    Lancement du scriptdans le dossier du script +
- +
-    python3 sender_rs_depth.py +
- +
-Avec VirtualEnv +
- +
-    Dans le dossier du projet: +
- +
-    python3 -m venv mon_env +
-    source mon_env/bin/activate +
-    python3 -m pip install numpy opencv-python pyfakewebcam pyrealsense2 +
- +
-    Lancement du script, dans le dossier du script +
- +
-    ./mon_env/bin/python3 python3 sender_rs_depth.py+
 """ """
  
Ligne 149: Ligne 126:
 import pyrealsense2 as rs import pyrealsense2 as rs
  
-GRAY_BACKGROUND = 153+ 
 +# Le faux device
 VIDEO = '/dev/video11' VIDEO = '/dev/video11'
 +
 +# Avec ou sans slider pour régler CLIPPING_DISTANCE_IN_MILLIMETER
 +SLIDER = 1
 +# Réglable avec le slider
 +# We will be removing the background of objects more than
 +# CLIPPING_DISTANCE_IN_MILLIMETER away
 +CLIPPING_DISTANCE_IN_MILLIMETER = 2000
 +
  
 class MyRealSense: class MyRealSense:
  
-    def __init__(self): +    def __init__(self, video, slider, clip): 
-        global VIDEO+        self.video = video 
 +        self.slider = slider 
 +        self.clip = clip 
         self.width = 1280         self.width = 1280
         self.height = 720         self.height = 720
Ligne 186: 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 201: Ligne 185:
  
         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)
 +
 +        if self.slider:
 +            self.create_slider()
 +
 +    def create_slider(self):
 +        cv2.namedWindow('controls')
 +        cv2.createTrackbar('background', 'controls', 1000, 8000,
 +                            self.remove_background_callback)
 +        cv2.setTrackbarPos('background', 'controls', self.clip)
 +        cv2.namedWindow('depth', cv2.WND_PROP_FULLSCREEN)
 +
 +    def remove_background_callback(self, value):
 +        if value != 1000:
 +            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 
  
         while self.pose_loop:         while self.pose_loop:
Ligne 227: Ligne 224:
  
             # Remove background - Set pixels further than clipping_distance to grey             # Remove background - Set pixels further than clipping_distance to grey
-            grey_color = GRAY_BACKGROUND 
             # 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), grey_color, color_image)+            bg_removed = np.where((depth_image_3d > clipping_distance) |\ 
 +                        (depth_image_3d <= 0), 0, color_image)
  
-            # Render images: 
-            #   depth align to color on left 
-            #   depth on right 
             depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image,             depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image,
                                                                    alpha=0.03),                                                                    alpha=0.03),
                                                                    cv2.COLORMAP_JET)                                                                    cv2.COLORMAP_JET)
 +            images = np.hstack((bg_removed, depth_colormap))
  
-            # # print(depth_colormap.shape) +            if self.slider: 
-            # # cv2.imshow('depth', depth_colormap+                cv2.imshow('depth', images) 
-            self.camera.schedule_frame(depth_colormap)+ 
 +            self.camera.schedule_frame(bg_removed)
  
             if cv2.waitKey(1) == 27:             if cv2.waitKey(1) == 27:
                 break                 break
  
-if __name__ == '__main__': 
-    mrs = MyRealSense() 
-    mrs.run() 
  
  
 +if __name__ == '__main__':
 +
 +    mrs = MyRealSense(VIDEO, SLIDER, CLIPPING_DISTANCE_IN_MILLIMETER)
 +    mrs.run()
 </file> </file>
      
streamer_des_images_opencv_avec_v4l2-loopback.1645874130.txt.gz · Dernière modification : 2022/02/26 11:15 de serge