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
Dernière révisionLes deux révisions suivantes
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/02/26 11:17] – [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 
-Commande non persistante, c'est perdu au reboot 
- 
-sudo modprobe v4l2loopback video_nr=11 
- 
-Necéssite pyrealsense2 
- 
-Sans VirtualEnv 
- 
-    python3 -m pip install numpy opencv-python pyfakewebcam pyrealsense2 
- 
-    Lancement du script, dans 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 
-""" 
- 
 import os import os
 import time import time
Ligne 149: Ligne 119:
 import pyrealsense2 as rs import pyrealsense2 as rs
  
 +# Le faux device
 +VIDEO = '/dev/video11'
 +# Avec ou sans slider pour régler GRAY_BACKGROUND
 +SLIDER = 1
 +# GRAY_BACKGROUND: Pas d'enregistrement de cette valeur
 +# si elle est modifiée par le slider, il faut le modifier ci-dessous
 GRAY_BACKGROUND = 153 GRAY_BACKGROUND = 153
-VIDEO = '/dev/video11' 
  
 class MyRealSense: class MyRealSense:
- 
     def __init__(self):     def __init__(self):
         global VIDEO         global VIDEO
 +        global SLIDER
 +        global GRAY_BACKGROUND
 +
         self.width = 1280         self.width = 1280
         self.height = 720         self.height = 720
Ligne 201: Ligne 178:
  
         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)         self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720)
 +
 +        if SLIDER:
 +            self.create_slider(GRAY_BACKGROUND)
 +
 +    def create_slider(self, gray):
 +        # # global GRAY_BACKGROUND
 +        cv2.namedWindow('controls')
 +        cv2.createTrackbar('background', 'controls', 1, 255,
 +                            self.gray_background_callback)
 +        cv2.setTrackbarPos('background', 'controls', gray)
 +        cv2.namedWindow('depth', cv2.WND_PROP_FULLSCREEN)
 +
 +    def gray_background_callback(self, value):
 +        global GRAY_BACKGROUND
 +        GRAY_BACKGROUND = 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 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 223: Ligne 214:
                 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())
  
             # 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) |\             bg_removed = np.where((depth_image_3d > self.clipping_distance) |\
-                                (depth_image_3d <= 0), grey_color, color_image)+                        (depth_image_3d <= 0), GRAY_BACKGROUND, 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 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:
Ligne 250: Ligne 240:
     mrs = MyRealSense()     mrs = MyRealSense()
     mrs.run()     mrs.run()
- 
- 
 </file> </file>
      
streamer_des_images_opencv_avec_v4l2-loopback.txt · Dernière modification : 2022/03/03 12:35 de serge