2021-12-30 12:51:33 +08:00
|
|
|
|
<p align="center">
|
2021-12-31 11:28:29 +08:00
|
|
|
|
<a href="https://gitee.com/CV_Lab/opencv_webcam">
|
2022-01-02 11:39:44 +08:00
|
|
|
|
<img src="https://gitee.com/CV_Lab/opencv_webcam/attach_files/932349/download/%E7%81%AB%E7%AE%AD.svg" alt="Simple Icons" width=64 height=64>
|
2021-12-30 12:51:33 +08:00
|
|
|
|
</a>
|
|
|
|
|
<h3 align="center">OpenCV Webcam Script</h3>
|
|
|
|
|
<p align="center">
|
|
|
|
|
基于OpenCV的Webcam程序,可用于视频帧采集、重塑尺寸等。具有安装便捷、操作简单等特点</p>
|
|
|
|
|
</p>
|
|
|
|
|
|
2022-01-02 11:39:44 +08:00
|
|
|
|
|
2021-12-30 12:51:33 +08:00
|
|
|
|
<p align="center">
|
2022-01-02 10:27:55 +08:00
|
|
|
|
<a href="https://pypi.org/project/opencv-webcam-script/"><img src="https://img.shields.io/badge/PyPi-v0.1-brightgreen?logo=pypi" alt="PyPi" /></a>
|
2022-01-02 10:24:20 +08:00
|
|
|
|
<a href="https://gitee.com/CV_Lab/opencv_webcam/releases/v0.1"><img src="https://img.shields.io/badge/latest%20version-v0.1-green" alt="Version" /></a>
|
2022-01-01 08:53:54 +08:00
|
|
|
|
<a href="https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script"><img src="https://img.shields.io/badge/docker-v0.1-blue?logo=docker" alt="Docker" /></a>
|
2021-12-30 12:51:33 +08:00
|
|
|
|
<a href="https://gitee.com/CV_Lab/opencv_webcam/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-GPL--3.0-blue" alt="License" /></a>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
2021-12-30 12:57:40 +08:00
|
|
|
|
|
2021-12-30 12:51:33 +08:00
|
|
|
|
<h3 align="center">更新走势</h3>
|
2021-12-30 12:58:58 +08:00
|
|
|
|
<hr>
|
2021-12-30 12:53:18 +08:00
|
|
|
|
|
2022-01-02 11:50:39 +08:00
|
|
|
|
- `2022-01-01` **:zap: [opencv-webcam-script v0.1 发行版](https://gitee.com/CV_Lab/opencv_webcam/releases/v0.1)正式上线**
|
2022-01-01 08:53:54 +08:00
|
|
|
|
- `2021-12-31` **:zap: [opencv-webcam-script v0.1 docker版](https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script)正式上线**
|
2021-12-30 12:53:18 +08:00
|
|
|
|
- `2021-12-29` **:zap: [opencv-webcam-script v0.1](https://pypi.org/project/opencv-webcam-script/0.1/)正式上线**
|
2021-12-29 18:10:01 +08:00
|
|
|
|
|
2021-12-30 12:51:33 +08:00
|
|
|
|
<h3 align="center">安装教程</h3>
|
2021-12-30 12:58:58 +08:00
|
|
|
|
<hr>
|
2021-12-29 18:10:01 +08:00
|
|
|
|
|
2021-12-30 12:51:33 +08:00
|
|
|
|
#### :white_check_mark: 方法一:Linux Shell安装(开发版)
|
2021-12-29 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
```shell
|
2021-12-29 18:07:09 +08:00
|
|
|
|
# 克隆项目
|
2021-12-29 19:56:07 +08:00
|
|
|
|
git clone https://gitee.com/CV_Lab/opencv_webcam.git
|
2021-12-29 16:47:23 +08:00
|
|
|
|
# 创建conda虚拟环境,以python 3.8为例
|
|
|
|
|
conda create -n ow python==3.8 # 虚拟环境名称为ow
|
|
|
|
|
conda activate ow # 激活虚拟环境
|
|
|
|
|
pip install -r ./requirements.txt -U # 安装OpenCV Webcam脚本
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-29 19:56:07 +08:00
|
|
|
|
#### :white_check_mark: 方法二:pip 快速安装(API版)
|
2021-12-29 16:47:23 +08:00
|
|
|
|
|
2021-12-29 19:56:07 +08:00
|
|
|
|
- 第一步:创建ow虚拟环境,参见方法一
|
|
|
|
|
- 第二步:执行pip指令
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
pip install opencv-webcam-script
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 第三步:编写python程序
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from opencv_webcam.opencv_webcam import webcam_opencv
|
|
|
|
|
# 直接使用webcam_opencv
|
|
|
|
|
webcam_opencv(device_index=0, quit_key='q', is_autoSaveFrame=False, frame_saveDir='./webcam', frame_nSave=1, is_headSaveFrame=False, frame_capKey='a', is_resizeFrame=False, resize_frame=[640, 480], resizeRatio_frame=1.0)
|
2021-12-29 16:47:23 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
2021-12-31 23:38:11 +08:00
|
|
|
|
|
2021-12-31 23:54:16 +08:00
|
|
|
|
#### :white_check_mark: 方法三:docker 镜像安装(容器版)
|
2021-12-31 23:38:11 +08:00
|
|
|
|
|
|
|
|
|
```shell
|
2021-12-31 23:54:16 +08:00
|
|
|
|
sudo docker pull zengdockerdocker/opencv-webcam-script:v0.1 # 镜像拉取
|
|
|
|
|
|
2021-12-31 23:38:11 +08:00
|
|
|
|
xhost +local:root # 配置xhost
|
2021-12-31 23:54:16 +08:00
|
|
|
|
sudo docker run --ipc=host -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY --device=/dev/video0:/dev/video0 zengdockerdocker/opencv-webcam-script:v0.1 # 进入容器
|
2021-12-31 23:38:11 +08:00
|
|
|
|
python3 opencv_webcam.py # 运行脚本程序
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-30 12:51:33 +08:00
|
|
|
|
<h3 align="center">使用教程</h3>
|
2021-12-30 12:58:58 +08:00
|
|
|
|
<hr>
|
2021-12-29 10:51:27 +08:00
|
|
|
|
|
|
|
|
|
#### :bulb: 常规调用
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 默认按q键退出
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-31 17:14:33 +08:00
|
|
|
|
#### :bulb: 摄像头选择
|
2021-12-31 17:13:04 +08:00
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 多摄像头切换示例
|
|
|
|
|
python opencv_webcam.py -dev 1
|
|
|
|
|
python opencv_webcam.py -dev 2
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-29 10:51:27 +08:00
|
|
|
|
#### :bulb: 设置退出键
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 默认按q键退出
|
|
|
|
|
# 设置z键退出
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -q z
|
2021-12-29 10:51:27 +08:00
|
|
|
|
# 设置k键退出
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -q k
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 自动保存帧
|
|
|
|
|
|
|
|
|
|
```shell
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -isasf
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 每隔n帧保存一次帧
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 每隔10帧保存一次帧
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -isasf -fns 10
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 手动保存帧
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 默认按a键捕获一帧
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -ishsf
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 自定义捕获键
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 设置z键为捕获键
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -ishsf -fck z
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 重塑帧尺寸(自定义宽高)
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 重塑宽度300 高度200
|
|
|
|
|
# 自动版
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -isasf -isrf -rf 300 200
|
2021-12-29 10:51:27 +08:00
|
|
|
|
# 手动版
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -ishsf -isrf -rf 300 200
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### :bulb: 重塑帧尺寸(自定义宽高缩放比)
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 宽高缩放比为0.5
|
|
|
|
|
# 自动版
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -isasf -isrf -rrf 0.5
|
2021-12-29 10:51:27 +08:00
|
|
|
|
# 手动版
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -ishsf -isrf -rrf 0.5
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-29 16:47:23 +08:00
|
|
|
|
#### :bulb: 设置保存路径
|
2021-12-29 10:51:27 +08:00
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 设置保存路径,默认保存路径为./WebcamFrame
|
2021-12-29 18:39:29 +08:00
|
|
|
|
python opencv_webcam.py -fsd custom_dir -isasf # 以自动版为例
|
2021-12-29 10:51:27 +08:00
|
|
|
|
```
|
|
|
|
|
|
2022-01-02 14:38:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 指令查询
|
|
|
|
|
|
|
|
|
|
```shell
|
2022-01-02 15:46:29 +08:00
|
|
|
|
python opencv_webcam.py --help
|
2022-01-02 14:38:46 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```shell
|
2022-01-03 14:00:56 +08:00
|
|
|
|
usage: opencv_webcam.py [-h] [--device DEVICE] [--quit QUIT] [--is_autoSaveFrame] [--is_handSaveFrame] [--is_resizeFrame] [--frame_saveDir FRAME_SAVEDIR] [--frame_nSave FRAME_NSAVE]
|
2022-01-02 15:46:29 +08:00
|
|
|
|
[--frame_capKey FRAME_CAPKEY] [--resize_frame RESIZE_FRAME [RESIZE_FRAME ...]] [--resizeRatio_frame RESIZERATIO_FRAME] [--frame_namePrefix FRAME_NAMEPREFIX]
|
2022-01-03 14:00:56 +08:00
|
|
|
|
[--frame_saveStyle FRAME_SAVESTYLE] [--jpg_quality JPG_QUALITY] [--png_quality PNG_QUALITY] [--pause PAUSE]
|
2022-01-02 14:38:46 +08:00
|
|
|
|
|
|
|
|
|
OpenCV Webcam Script
|
|
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
|
--device DEVICE, -dev DEVICE
|
|
|
|
|
device index for webcam
|
|
|
|
|
--quit QUIT, -q QUIT quit key for webcam
|
|
|
|
|
--is_autoSaveFrame, -isasf
|
|
|
|
|
is auto save frame
|
2022-01-03 14:00:56 +08:00
|
|
|
|
--is_handSaveFrame, -ishsf
|
|
|
|
|
is hand save frame
|
2022-01-02 14:38:46 +08:00
|
|
|
|
--is_resizeFrame, -isrf
|
|
|
|
|
is resize frame
|
|
|
|
|
--frame_saveDir FRAME_SAVEDIR, -fsd FRAME_SAVEDIR
|
|
|
|
|
save frame dir
|
|
|
|
|
--frame_nSave FRAME_NSAVE, -fns FRAME_NSAVE
|
|
|
|
|
n frames save a frame (auto save frame)
|
|
|
|
|
--frame_capKey FRAME_CAPKEY, -fck FRAME_CAPKEY
|
2022-01-03 14:00:56 +08:00
|
|
|
|
frame capture key (hand save frame)
|
2022-01-02 14:38:46 +08:00
|
|
|
|
--resize_frame RESIZE_FRAME [RESIZE_FRAME ...], -rf RESIZE_FRAME [RESIZE_FRAME ...]
|
|
|
|
|
resize frame save
|
|
|
|
|
--resizeRatio_frame RESIZERATIO_FRAME, -rrf RESIZERATIO_FRAME
|
|
|
|
|
resize ratio frame save
|
2022-01-02 15:46:29 +08:00
|
|
|
|
--frame_namePrefix FRAME_NAMEPREFIX, -fnp FRAME_NAMEPREFIX
|
|
|
|
|
frame name prefix
|
|
|
|
|
--frame_saveStyle FRAME_SAVESTYLE, -fss FRAME_SAVESTYLE
|
|
|
|
|
frame save style
|
|
|
|
|
--jpg_quality JPG_QUALITY, -jq JPG_QUALITY
|
|
|
|
|
frame save jpg quality (0-100) default 95
|
|
|
|
|
--png_quality PNG_QUALITY, -pq PNG_QUALITY
|
|
|
|
|
frame save jpg quality (0-9) default 3
|
2022-01-03 14:00:56 +08:00
|
|
|
|
--pause PAUSE, -p PAUSE
|
|
|
|
|
webcam pause
|
2022-01-02 14:38:46 +08:00
|
|
|
|
```
|
|
|
|
|
|