web-dev-qa-db-fra.com

VIDEOIO ERROR: V4L2: Le format de pixel de l'image entrante n'est pas pris en charge par OpenCV Impossible d'arrêter le flux: périphérique ou ressource occupé

En exécutant un code privé qui lit les données de la webcam, j'obtiens l'erreur suivante:

Loading weights from handyolo/weights/000010.weights... Done!
INFO:exp11_fm64_iter1_l2_rmsprop_feaadd_zrel3_transformer_Test:Creating instance of the ImageHeatmapsPose2dZrelZAll_FPN model.
INFO:exp11_fm64_iter1_l2_rmsprop_feaadd_zrel3_transformer_Test:n_iter: 1
INFO:exp11_fm64_iter1_l2_rmsprop_feaadd_zrel3_transformer_Test:improvement_per_itr: 0.01
INFO:exp11_fm64_iter1_l2_rmsprop_feaadd_zrel3_transformer_Test:beta: 5.0
INFO:exp11_fm64_iter1_l2_rmsprop_feaadd_zrel3_transformer_Test:Creating instance of L1 Loss.
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream: Device or resource busy
Error getting frame from device 0

Voici les informations de la caméra:

$ v4l2-ctl -d /dev/video0 --all
Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : HD Pro Webcam C920
    Bus info      : usb-0000:00:14.0-9
    Driver version: 4.13.13
    Capabilities  : 0x84200001
        Video Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps   : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height      : 320/180
    Pixel Format      : 'YUYV'
    Field             : None
    Bytes per Line    : 640
    Size Image        : 115200
    Colorspace        : sRGB
    Transfer Function : Default
    YCbCr Encoding    : Default
    Quantization      : Default
    Flags             : 
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 320, Height 180
    Default     : Left 0, Top 0, Width 320, Height 180
    Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 320, Height 180
Selection: crop_bounds, Left 0, Top 0, Width 320, Height 180
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 30.000 (30/1)
    Read buffers     : 0
                     brightness (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation (int)    : min=0 max=255 step=1 default=128 value=128
 white_balance_temperature_auto (bool)   : default=1 value=1
                           gain (int)    : min=0 max=255 step=1 default=0 value=132
           power_line_frequency (menu)   : min=0 max=2 default=2 value=2
      white_balance_temperature (int)    : min=2000 max=6500 step=1 default=4000 value=3255 flags=inactive
                      sharpness (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto (menu)   : min=0 max=3 default=3 value=3
              exposure_absolute (int)    : min=3 max=2047 step=1 default=250 value=333 flags=inactive
         exposure_auto_priority (bool)   : default=0 value=1
                   pan_absolute (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute (int)    : min=0 max=250 step=5 default=0 value=0 flags=inactive
                     focus_auto (bool)   : default=1 value=1
                  zoom_absolute (int)    : min=100 max=500 step=1 default=100 value=100
                      led1_mode (menu)   : min=0 max=3 default=0 value=3
                 led1_frequency (int)    : min=0 max=255 step=1 default=0 value=0



$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'H264' (compressed)
    Name        : H.264

    Index       : 2
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG

Comment puis-je réparer cela?

Aussi, en essayant d'obtenir la vidéo de guvcview, j'obtiens l'erreur suivante:

$ guvcview
GUVCVIEW: version 2.0.2
GUVCVIEW: couldn't open /home/mona/.config/guvcview2/video0 for read: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
V4L2_CORE: (UVCIOC_CTRL_MAP) Error: No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
libv4l2: error setting pixformat: Device or resource busy
V4L2_CORE: (VIDIOC_S_FORMAT) Unable to set format: Device or resource busy
GUCVIEW: could not set the defined stream format
GUCVIEW: trying first listed stream format
libv4l2: error setting pixformat: Device or resource busy
V4L2_CORE: (VIDIOC_S_FORMAT) Unable to set format: Device or resource busy
GUCVIEW: also could not set the first listed stream format
GUVCVIEW: Video capture failed
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
V4L2_CORE: (VIDIOC_S_PARM) error: Device or resource busy
V4L2_CORE: Unable to set 1/30 fps
GUVCVIEW: (status) saving video to /home/mona/my_video-1.mkv
ENCODER: add stream 0 to stream list
ENCODER: add stream 1 to stream list
ENCODER: (matroska) add seekhead entry 0 (max 10)
ENCODER: (matroska) add seekhead entry 1 (max 10)
AUDIO: (portaudio) Aborting audio stream
AUDIO: Closing audio stream...
ENCODER: (matroska) closing context
ENCODER: (matroska) closing cluster
ENCODER: (matroska)write seekhead
ENCODER: (matroska) end duration = 6922 (6922.000000) 
^CGUVCVIEW Caught signal 2
^CGUVCVIEW Caught signal 2

jusqu'à présent débranché et rebranché la webcam, utilisé du fromage et maintenant je reçois la vidéo:

$ cheese &

Mais maintenant, en exécutant le code, je reçois cette nouvelle erreur:

VIDEOIO ERROR: V4L: index 0 is not correct!
Error getting frame from device 0

Avant cela, la lumière de la caméra était bleue et maintenant, aucune lumière n’est allumée.

donc ma webcam est sur le périphérique 014 et je l’utilise pour la capture vidéo en OpenCV:

$ Sudo lsusb  | grep -i cam
Bus 003 Device 014: ID 046d:082d Logitech, Inc. HD Pro Webcam C920

Voici le code:

if USE_CAMERA:
    cap = cv.VideoCapture(args.device)

Et je passe 014 comme argument. Je reçois cette erreur:

VIDEOIO ERROR: V4L: index 14 is not correct!
Error getting frame from device 14
3
Mona Jalal

Commencez par débrancher et connecter la webcam USB, puis utilisez la commande suivante pour rechercher le numéro de périphérique correspondant à la webcam et utilisez le numéro de port approprié:

$ ls /dev/video*
/dev/video1
1
Mona Jalal

Dans mon cas, il s'agissait d'un problème de version d'OpenCV. J'ai abaissé sa version de 4.0 à 3.4 et cela a fonctionné pour moi. Depuis que j'ai installé mon OpenCv avec pip auparavant, je l’ai rétrogradé de la manière suivante:

pip uninstall opencv-python
pip install opencv-python==3.4.0.12
1
Sherzod