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édenteProchaine révision | Révision précédente | ||
| streamer_des_images_opencv_avec_v4l2-loopback [2022/02/25 09:07] – [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 14: | Ligne 14: | ||
| * https:// | * https:// | ||
| - | =====Installation==== | + | =====Sources des exemples===== |
| - | A voir, nécessaire mais peut-être pas suffisant: | + | * **[[https:// |
| - | sudo apt install v4l2loopback-utils | + | |
| - | + | ||
| - | <code bash> | + | |
| - | sudo apt install python3-pip | + | |
| - | python3 -m pip install --upgrade pip | + | |
| - | sudo apt install python3-venv | + | |
| - | cd /le/ | + | ====Installation==== |
| - | python3 | + | Voir le README ci-dessus. |
| - | source mon_env/ | + | |
| - | python3 -m pip install opencv-python pyfakewebcam | + | |
| - | </ | + | |
| =====Exemple simple pour tester===== | =====Exemple simple pour tester===== | ||
| <file python cam_relay.py> | <file python cam_relay.py> | ||
| - | """ | ||
| - | Insert the v4l2loopback kernel module. | ||
| - | modprobe v4l2loopback devices=2 | ||
| - | will create two fake webcam devices | ||
| - | """ | ||
| - | import time | ||
| import pyfakewebcam | import pyfakewebcam | ||
| import cv2 | import cv2 | ||
| Ligne 42: | Ligne 27: | ||
| cap = cv2.VideoCapture(0) | cap = cv2.VideoCapture(0) | ||
| - | camera = pyfakewebcam.FakeWebcam('/ | + | camera = pyfakewebcam.FakeWebcam('/ |
| while True: | while True: | ||
| ret, image = cap.read() | ret, image = cap.read() | ||
| Ligne 50: | Ligne 36: | ||
| if cv2.waitKey(1) == 27: | if cv2.waitKey(1) == 27: | ||
| break | break | ||
| - | |||
| - | """ | ||
| - | Run the following command to see the output of the fake webcam. | ||
| - | ffplay /dev/video1 | ||
| - | or open a camera in vlc | ||
| - | """ | ||
| </ | </ | ||
| - | Exécuter le script avec: | + | Run the following command to see the output of the fake webcam.\\ |
| - | cd / | + | ffplay /dev/video11\\ |
| - | modprobe v4l2loopback devices=2 | + | or open the camera 11 in vlc |
| - | | + | |
| - | Dans un autre terminal | + | |
| - | | + | |
| - | Il faudra peut-être adapter les numéro de /dev/video | + | |
| - | + | ||
| ===== Profondeur d'une OAK-D Lite ===== | ===== Profondeur d'une OAK-D Lite ===== | ||
| - | < | ||
| - | cd / | ||
| - | source mon_env/ | ||
| - | python3 -m pip install depthai numpy | ||
| - | </ | ||
| - | |||
| <file python sender_oak_depth.py> | <file python sender_oak_depth.py> | ||
| import cv2 | import cv2 | ||
| Ligne 80: | Ligne 49: | ||
| pipeline = dai.Pipeline() | pipeline = dai.Pipeline() | ||
| + | |||
| # Define a source - two mono (grayscale) cameras | # Define a source - two mono (grayscale) cameras | ||
| left = pipeline.createMonoCamera() | left = pipeline.createMonoCamera() | ||
| Ligne 113: | Ligne 83: | ||
| depth.disparity.link(xout.input) | depth.disparity.link(xout.input) | ||
| - | camera = pyfakewebcam.FakeWebcam('/ | + | camera = pyfakewebcam.FakeWebcam('/ |
| with dai.Device(pipeline) as device: | with dai.Device(pipeline) as device: | ||
| Ligne 135: | Ligne 105: | ||
| break | break | ||
| </ | </ | ||
| - | Exécuter le script avec: | + | |
| - | cd / | + | Ouvrir /dev/video11 |
| - | modprobe v4l2loopback devices=2 | + | |
| - | ./ | + | |
| - | Ouvrir /dev/video1 | + | |
| {{ : | {{ : | ||
| - | ====Profondeur d'une RealSense D455==== | + | =====Profondeur d'une RealSense D455===== |
| Pour l' | Pour l' | ||
| - | <code bash> | ||
| - | cd / | ||
| - | source mon_env/ | ||
| - | python3 -m pip install | ||
| - | </ | ||
| <file python sender_rs_depth.py> | <file python sender_rs_depth.py> | ||
| - | |||
| """ | """ | ||
| - | Créer des devices | + | Voir https://github.com/ |
| - | Commande non persistante, | + | |
| - | + | ||
| - | sudo modprobe v4l2loopback video_nr=10, | + | |
| + | Suppression du fond, voir | ||
| + | https:// | ||
| """ | """ | ||
| Ligne 167: | Ligne 126: | ||
| import pyrealsense2 as rs | import pyrealsense2 as rs | ||
| + | |||
| + | # Le faux device | ||
| + | VIDEO = '/ | ||
| + | |||
| + | # 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): |
| + | self.video = video | ||
| + | self.slider = slider | ||
| + | self.clip = clip | ||
| self.width = 1280 | self.width = 1280 | ||
| self.height = 720 | self.height = 720 | ||
| Ligne 202: | 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 216: | Ligne 184: | ||
| f" | f" | ||
| - | self.camera = pyfakewebcam.FakeWebcam('/ | + | self.camera = pyfakewebcam.FakeWebcam(VIDEO, 1280, 720) |
| + | |||
| + | if self.slider: | ||
| + | self.create_slider() | ||
| + | |||
| + | def create_slider(self): | ||
| + | cv2.namedWindow(' | ||
| + | cv2.createTrackbar(' | ||
| + | self.remove_background_callback) | ||
| + | cv2.setTrackbarPos(' | ||
| + | cv2.namedWindow(' | ||
| + | |||
| + | def remove_background_callback(self, | ||
| + | if value != 1000: | ||
| + | self.clip = int(value) | ||
| def run(self): | def run(self): | ||
| """ | """ | ||
| + | |||
| while self.pose_loop: | while self.pose_loop: | ||
| Ligne 229: | Ligne 212: | ||
| aligned_frames = self.align.process(frames) | aligned_frames = self.align.process(frames) | ||
| - | # Get aligned frames | + | # aligned_depth_frame is a 640x480 depth image |
| - | aligned_depth_frame = aligned_frames.get_depth_frame() | + | aligned_depth_frame = aligned_frames.get_depth_frame() |
| color_frame = aligned_frames.get_color_frame() | color_frame = aligned_frames.get_color_frame() | ||
| Ligne 241: | Ligne 224: | ||
| # Remove background - Set pixels further than clipping_distance to grey | # Remove background - Set pixels further than clipping_distance to grey | ||
| - | | + | |
| - | 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), grey_color, color_image) | + | clipping_distance = self.clip / (1000*self.depth_scale) |
| + | bg_removed = np.where((depth_image_3d > clipping_distance) |\ | ||
| + | | ||
| - | | + | depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, |
| - | # depth align to color on left | + | alpha=0.03), |
| - | # depth on right | + | cv2.COLORMAP_JET) |
| - | | + | images = np.hstack((bg_removed, |
| - | | + | |
| - | # # cv2.imshow(' | + | cv2.imshow(' |
| - | 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__ == ' | if __name__ == ' | ||
| - | mrs = MyRealSense() | ||
| - | mrs.run() | ||
| + | mrs = MyRealSense(VIDEO, | ||
| + | mrs.run() | ||
| </ | </ | ||
| - | |||
| - | Exécuter le script avec: | ||
| - | cd / | ||
| - | modprobe v4l2loopback devices=2 | ||
| - | ./ | ||
| | | ||
| - | ===Réception=== | + | =====Réception===== |
| Ouvrir / | Ouvrir / | ||
streamer_des_images_opencv_avec_v4l2-loopback.1645780078.txt.gz · Dernière modification : de serge
