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 13:11] – [Exemple simple pour tester] serge | streamer_des_images_opencv_avec_v4l2-loopback [2022/03/03 12:35] (Version actuelle) – [Profondeur d'une RealSense D455] serge | ||
---|---|---|---|
Ligne 15: | Ligne 15: | ||
=====Sources des exemples===== | =====Sources des exemples===== | ||
- | * **** | + | * **[[https:// |
- | =====Installation==== | + | |
- | A voir, nécessaire mais peut-être pas suffisant: | + | |
- | 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> | ||
- | """ | ||
- | Créer un device / | ||
- | Commande non persistante, | ||
- | |||
- | sudo modprobe v4l2loopback video_nr=11 | ||
- | |||
- | |||
- | Sans VirtualEnv | ||
- | |||
- | python3 -m pip install numpy opencv-python pyfakewebcam | ||
- | |||
- | Lancement du script, dans le dossier du script | ||
- | |||
- | python3 cam_relay.py | ||
- | |||
- | Avec VirtualEnv | ||
- | |||
- | Dans le dossier du projet: | ||
- | |||
- | python3 -m venv mon_env | ||
- | source mon_env/ | ||
- | python3 -m pip install numpy opencv-python pyfakewebcam | ||
- | |||
- | Lancement du script, dans le dossier du script | ||
- | |||
- | ./ | ||
- | |||
- | """ | ||
- | |||
import pyfakewebcam | import pyfakewebcam | ||
import cv2 | import cv2 | ||
Ligne 76: | 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.\\ |
- | Run the following command to see the output of the fake webcam. | + | ffplay / |
- | + | ||
- | ffplay / | + | |
or open the camera 11 in vlc | or open the camera 11 in vlc | ||
- | """ | ||
- | </ | ||
- | |||
- | | ||
===== Profondeur d'une OAK-D Lite ===== | ===== Profondeur d'une OAK-D Lite ===== | ||
<file python sender_oak_depth.py> | <file python sender_oak_depth.py> | ||
- | """ | ||
- | Créer un device / | ||
- | Commande non persistante, | ||
- | |||
- | sudo modprobe v4l2loopback video_nr=11 | ||
- | |||
- | Necéssite depthai | ||
- | |||
- | Sans VirtualEnv | ||
- | |||
- | python3 -m pip install numpy opencv-python pyfakewebcam depthai | ||
- | |||
- | Lancement du script, dans le dossier du script | ||
- | |||
- | python3 sender_oak_depth.py | ||
- | |||
- | Avec VirtualEnv | ||
- | |||
- | Dans le dossier du projet: | ||
- | |||
- | python3 -m venv mon_env | ||
- | source mon_env/ | ||
- | python3 -m pip install numpy opencv-python pyfakewebcam depthai | ||
- | |||
- | Lancement du script, dans le dossier du script | ||
- | |||
- | ./ | ||
- | |||
- | """ | ||
- | |||
import cv2 | import cv2 | ||
import depthai as dai | import depthai as dai | ||
import numpy as np | import numpy as np | ||
import pyfakewebcam | import pyfakewebcam | ||
- | |||
pipeline = dai.Pipeline() | pipeline = dai.Pipeline() | ||
Ligne 188: | Ligne 112: | ||
<file python sender_rs_depth.py> | <file python sender_rs_depth.py> | ||
- | |||
""" | """ | ||
- | Créer un device | + | Voir https://github.com/sergeLabo/fakewebcam |
- | Commande non persistante, | + | |
- | + | ||
- | 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 | + | |
- | | + | Suppression du fond, voir |
+ | https:// | ||
""" | """ | ||
Ligne 225: | Ligne 126: | ||
import pyrealsense2 as rs | import pyrealsense2 as rs | ||
- | GRAY_BACKGROUND = 153 | + | |
+ | # Le faux device | ||
VIDEO = '/ | 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.slider = slider | ||
+ | self.clip = clip | ||
self.width = 1280 | self.width = 1280 | ||
self.height = 720 | self.height = 720 | ||
Ligne 262: | 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 277: | Ligne 185: | ||
self.camera = pyfakewebcam.FakeWebcam(VIDEO, | self.camera = pyfakewebcam.FakeWebcam(VIDEO, | ||
+ | |||
+ | 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): | ||
""" | """ | ||
- | global GRAY_BACKGROUND | ||
while self.pose_loop: | while self.pose_loop: | ||
Ligne 303: | 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_3d = np.dstack((depth_image, | ||
- | bg_removed = np.where((depth_image_3d > self.clipping_distance) |\ | + | |
- | (depth_image_3d <= 0), grey_color, color_image) | + | |
+ | (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, | ||
| | ||
| | ||
+ | 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: | ||
Ligne 326: | Ligne 246: | ||
if __name__ == ' | if __name__ == ' | ||
- | mrs = MyRealSense() | ||
- | mrs.run() | ||
- | |||
+ | mrs = MyRealSense(VIDEO, | ||
+ | mrs.run() | ||
</ | </ | ||
| |
streamer_des_images_opencv_avec_v4l2-loopback.1645794677.txt.gz · Dernière modification : 2022/02/25 13:11 de serge