摘要-针对ubantu20
sudo apt install v4l-utils
v4l2-ctl --list-devices
- cv2 install on ubantu20
```
针对ubantu20
sudo apt install v4l-utils
v4l2-ctl --list-devices
pip uninstall opencv-python
conda install pyqt
pip install opencv-python==4.1.2.30
```
(py38) itdb@ai:/opt/aisty/doc/aitools$ /opt/aisty/app/anaconda3/envs/py38/bin/python /opt/aisty/doc/aitools/case/face/04-tt.py
VIDEOIO ERROR: V4L2: Could not obtain specifics of capture window.
[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (802) open VIDEOIO ERROR: V4L: can't open camera by index 1
/dev/video1 does not support memory mapping
Traceback (most recent call last):
File "/opt/aisty/doc/aitools/case/face/04-tt.py", line 18, in
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转换为灰度图
cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
查看摄像头编号
v4l2-ctl --list-devices
(base) itdb@ai:~/Desktop$ find /lib/modules/ -name "*v4l2*.ko"
/lib/modules/5.8.0-59-generic/kernel/drivers/media/v4l2-core/v4l2-dv-timings.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/v4l2-core/v4l2-flash-led-class.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/v4l2-core/v4l2-fwnode.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/v4l2-core/v4l2-mem2mem.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/i2c/adv7511-v4l2.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/common/v4l2-tpg/v4l2-tpg.ko
/lib/modules/5.8.0-59-generic/kernel/drivers/media/common/videobuf2/videobuf2-v4l2.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/v4l2-core/v4l2-dv-timings.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/v4l2-core/v4l2-flash-led-class.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/v4l2-core/v4l2-fwnode.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/v4l2-core/v4l2-mem2mem.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/i2c/adv7511-v4l2.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/common/v4l2-tpg/v4l2-tpg.ko
/lib/modules/5.8.0-43-generic/kernel/drivers/media/common/videobuf2/videobuf2-v4l2.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/v4l2-core/v4l2-dv-timings.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/v4l2-core/v4l2-flash-led-class.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/v4l2-core/v4l2-fwnode.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/v4l2-core/v4l2-mem2mem.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/i2c/adv7511-v4l2.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/common/v4l2-tpg/v4l2-tpg.ko
/lib/modules/5.8.0-63-generic/kernel/drivers/media/common/videobuf2/videobuf2-v4l2.ko
(base) itdb@ai:~/Desktop$ sudo apt-get install v4l2-ctl
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package v4l2-ctl
(base) itdb@ai:~/Desktop$ v4l2-ctl --list-devices
Command 'v4l2-ctl' not found, but can be installed with:
sudo apt install v4l-utils
(base) itdb@ai:~/Desktop$ sudo apt install v4l-utils
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
linux-headers-5.8.0-43-generic linux-hwe-5.8-headers-5.8.0-43 linux-image-5.8.0-43-generic linux-modules-5.8.0-43-generic
linux-modules-extra-5.8.0-43-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libv4l2rds0
The following NEW packages will be installed:
libv4l2rds0 v4l-utils
0 upgraded, 2 newly installed, 0 to remove and 15 not upgraded.
Need to get 602 kB of archives.
After this operation, 2,274 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 libv4l2rds0 amd64 1.18.0-2build1 [15.8 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 v4l-utils amd64 1.18.0-2build1 [586 kB]
Fetched 602 kB in 3s (180 kB/s)
Selecting previously unselected package libv4l2rds0:amd64.
(Reading database … 252070 files and directories currently installed.)
Preparing to unpack …/libv4l2rds0_1.18.0-2build1_amd64.deb …
Unpacking libv4l2rds0:amd64 (1.18.0-2build1) …
Selecting previously unselected package v4l-utils.
Preparing to unpack …/v4l-utils_1.18.0-2build1_amd64.deb …
Unpacking v4l-utils (1.18.0-2build1) …
Setting up libv4l2rds0:amd64 (1.18.0-2build1) …
Setting up v4l-utils (1.18.0-2build1) …
Processing triggers for libc-bin (2.31-0ubuntu9.2) …
Processing triggers for man-db (2.9.1-1) …
(base) itdb@ai:~/Desktop$ v4l2-ctl --list-devices
Synaptics RMI4 Touch Sensor (rmi4:rmi4-00.fn54):
/dev/v4l-touch0
USB Camera: USB Camera (usb-0000:00:14.0-1):
/dev/video2
/dev/video3
Integrated Camera: Integrated C (usb-0000:00:14.0-6):
/dev/video0
/dev/video1
Integrated Camera 电脑集成摄像机的编号是0,1
外部插的USB摄像机编号是2,3
编号改为2,即可调用外部摄像头
# 摄像头
cap = cv2.VideoCapture(2)
手机扫一扫
移动阅读更方便
你可能感兴趣的文章