相机打不开,提示设备或资源忙

 调试开发摄像头,难免会出现程序崩掉,没有能够释放摄像头资源,导致再次打开摄像头失败,出现 Device or resource busy, 设备或资源忙。错误如下:

[3:44:57.208889526] [2819]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[3:44:57.227755605] [2822]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[3:44:57.228626716] [2822] ERROR V4L2 v4l2_device.cpp:353 'imx477 6-001a': Unable to set controls: Device or resource busy
[3:44:57.238122459] [2822]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx477@1a to CFE device /dev/media0 and ISP device /dev/media2 using PiSP variant BCM2712_C0
[3:44:57.238191756] [2822]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[3:44:57.247154628] [2822]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/imx477@1a to CFE device /dev/media1 and ISP device /dev/media3 using PiSP variant BCM2712_C0
[3:44:57.249098944] [2819]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[3:44:57.267723744] [2827]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[3:44:57.268346911] [2827] ERROR V4L2 v4l2_device.cpp:353 'imx477 6-001a': Unable to set controls: Device or resource busy
[3:44:57.277560432] [2827]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx477@1a to CFE device /dev/media0 and ISP device /dev/media2 using PiSP variant BCM2712_C0
[3:44:57.277625210] [2827]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[3:44:57.287310249] [2827]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/imx477@1a to CFE device /dev/media1 and ISP device /dev/media3 using PiSP variant BCM2712_C0
[3:44:57.288244787] [2819]  INFO Camera camera.cpp:990 Pipeline handler in use by another process
Camera __init__ sequence did not complete.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 254, in __init__
    self._open_camera()
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 465, in _open_camera
    self.camera.acquire()
RuntimeError: Failed to acquire camera: Device or resource busy

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/camnet/mjpeg_server.py", line 86, in <module>
    picam2 = Picamera2()
             ^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 266, in __init__
    raise RuntimeError("Camera __init__ sequence did not complete.")
RuntimeError: Camera __init__ sequence did not complete.

当然,解决该问题,最简单的办法就是重启电脑。 

我们仔细查看错误,发现是 /dev/media* 设备打不开,用该命令查看资源被占用情况:

lsof /dev/media2

显示: 

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
pipewire  1427   pi   59u   CHR  238,2      0t0  572 /dev/media2
wireplumb 1430   pi   39u   CHR  238,2      0t0  572 /dev/media2
python    2535   pi   12uW  CHR  238,2      0t0  572 /dev/media2

看到有一个python程序,PID为2535占用了资源,可以使用该命令详细查看该PID情况:

ps axl | grep 2535

 结束掉该进程即可释放资源:

kill -9 2535

再次查看 lsof /dev/media2

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
pipewire  1427   pi   59u   CHR  238,2      0t0  572 /dev/media2
wireplumb 1430   pi   39u   CHR  238,2      0t0  572 /dev/media2
[1]+  Killed                  python mjpeg_server_2.py

看到该进程已经被kill掉了,现在可以正常使用相机了。 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值