Go to file
13339479676 ff540f46fd jupyter update 2022-01-17 08:29:52 +08:00
utils v03 args yaml update 02 2022-01-16 07:58:53 +08:00
v_change v_change update 2022-01-16 17:07:26 +08:00
.dockerignore dockerignore update 2022-01-16 12:58:36 +08:00
.gitignore gitignore update 2022-01-16 07:32:41 +08:00
Dockerfile readme jupyter update 2022-01-07 13:15:09 +08:00
LICENSE Initial commit 2021-12-29 02:05:40 +00:00
README.md jupyter update 2022-01-17 08:29:52 +08:00
__init__.py init update 2022-01-06 11:38:51 +08:00
codeCheck.md code check update 2022-01-16 18:29:43 +08:00
opencv_webcam.py v03 update 2022-01-16 08:39:24 +08:00
requirements.txt requirements update 2022-01-16 13:05:13 +08:00
tutorial.ipynb jupyter update 2022-01-17 08:27:18 +08:00
v03.md v03 readme update 2022-01-16 12:55:15 +08:00

README.md

Simple Icons

OpenCV Webcam Script

基于OpenCV的Webcam程序可用于视频帧采集、重塑尺寸等。具有安装便捷、操作简单等特点

PyPi Releases Version Docker Jupyter License

更新走势


安装教程


方法一Linux Shell安装开发版

  • 第一步:克隆项目
git clone https://gitee.com/CV_Lab/opencv_webcam.git # 克隆项目
  • 第二步:创建虚拟环境
# 创建conda虚拟环境以python 3.8为例
conda create -n ow python==3.8 # 虚拟环境名称为ow
conda activate ow # 激活虚拟环境
  • 第三步:安装脚本
pip install -r ./requirements.txt -U # 安装OpenCV Webcam脚本

方法二pip 快速安装PyPi版

  • 第一步创建ow虚拟环境参见方法一
  • 第二步执行pip指令
pip install opencv-webcam-script==0.3.0
  • 第三步编写python程序
from opencv_webcam.opencv_webcam import webcam_opencv
# 例举两个功能
webcam_opencv() # 常规调用
webcam_opencv(is_autoSaveFrame=True) # 自动保存帧

方法三docker 镜像安装(容器版)

  • 第一步:下载镜像
sudo docker pull zengdockerdocker/opencv-webcam-script:v0.2 # 镜像拉取
  • 第二步:创建容器
xhost +local:root # 配置xhost重要
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.2 # 进入容器
  • 第三步:运行程序
python3 opencv_webcam.py # 运行脚本程序
python3 opencv_webcam.py -isasf # 自动保存帧

使用教程


💡 常规调用

# 默认按q键退出
python opencv_webcam.py

💡 设备选择

# 多摄像头切换示例默认为0
python opencv_webcam.py -dev 0
python opencv_webcam.py -dev 1
python opencv_webcam.py -dev 2
# RTSP
python opencv_webcam.py -dev rtsp://username:password@xxx.xxx.xxx

💡 设置退出键

# 默认按q键退出
python opencv_webcam.py -q z # 设置z键退出
python opencv_webcam.py -q k # 设置k键退出

💡 自动保存帧

python opencv_webcam.py -isasf

💡 每隔n帧保存一次帧

# 每隔10帧保存一次帧
python opencv_webcam.py -isasf -fns 10

💡 手动保存帧

# 默认按a键捕获一帧
python opencv_webcam.py -ishsf

💡 自定义捕获键

# 设置z键为捕获键默认为a键
python opencv_webcam.py -ishsf -fck z

💡 重塑帧尺寸(自定义宽高)

# 重塑宽度300 高度200
python opencv_webcam.py -isasf -isrf -rf 300 200 # 自动版
python opencv_webcam.py -ishsf -isrf -rf 300 200 # 手动版

💡 重塑帧尺寸(自定义宽高缩放比)

# 宽高缩放比为0.5
python opencv_webcam.py -isasf -isrf -rrf 0.5 # 自动版
python opencv_webcam.py -ishsf -isrf -rrf 0.5 # 手动版

💡 自定义保存路径

# 设置保存路径,默认保存路径为./WebcamFrame
python opencv_webcam.py -fsd custom_dir -isasf # 以自动版为例

💡 自定义帧目录名称

# 设置帧目录名称默认保存路径为frames
python opencv_webcam.py -fdn frames_custom -isasf # 以自动版为例

💡 自定义帧名前缀

# 设置帧图片的前缀名称
python opencv_webcam.py -isasf -fnp webcam

💡 设置帧保存格式

# 设置JPG质量为100默认为95
python opencv_webcam.py -isasf -fss jpg -jq 100
# 设置PNG质量为5默认为3
python opencv_webcam.py -isasf -fss png -jq 5

💡 设置暂停键

# 设置w键为暂停键默认为p键
python opencv_webcam.py -p w # 按任意键继续

💡 设置保存帧数

# 设置保存100帧
python opencv_webcam.py -isasf -afn 100

💡 日志设置

# 日志文件默认保存在项目根目录test.log
python opencv_webcam.py
# 设置日志文件名称及类型,类型包括.log、.txt、.data
python opencv_webcam.py -ln test02.txt
# 设置日志保存方式,,默认为追加模式
python opencv_webcam.py -lm w # 设置为覆盖模式

💡 指令查询

# 查询脚本参数
python opencv_webcam.py --help
指令查询结果
usage: opencv_webcam.py [-h] [--device DEVICE] [--quit QUIT] [--is_autoSaveFrame] [--is_handSaveFrame]
                        [--is_resizeFrame] [--frame_saveDir FRAME_SAVEDIR]
                        [--frame_dirName FRAME_DIRNAME] [--frame_nSave FRAME_NSAVE]
                        [--frame_capKey FRAME_CAPKEY] [--resize_frame RESIZE_FRAME [RESIZE_FRAME ...]]
                        [--resizeRatio_frame RESIZERATIO_FRAME] [--frame_namePrefix FRAME_NAMEPREFIX]
                        [--frame_saveStyle FRAME_SAVESTYLE] [--jpg_quality JPG_QUALITY]
                        [--png_quality PNG_QUALITY] [--pause PAUSE] [--auto_frameNum AUTO_FRAMENUM]
                        [--logName LOGNAME] [--logMode LOGMODE]

OpenCV Webcam Script v0.3

optional arguments:
  -h, --help            show this help message and exit
  --device DEVICE, -dev DEVICE
                        device index for webcam, 0 or rtsp
  --quit QUIT, -q QUIT  quit key for webcam
  --is_autoSaveFrame, -isasf
                        is auto save frame
  --is_handSaveFrame, -ishsf
                        is hand save frame
  --is_resizeFrame, -isrf
                        is resize frame
  --frame_saveDir FRAME_SAVEDIR, -fsd FRAME_SAVEDIR
                        save frame dir
  --frame_dirName FRAME_DIRNAME, -fdn FRAME_DIRNAME
                        save frame dir name
  --frame_nSave FRAME_NSAVE, -fns FRAME_NSAVE
                        n frames save a frame (auto save frame)
  --frame_capKey FRAME_CAPKEY, -fck FRAME_CAPKEY
                        frame capture key (hand save frame)
  --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
  --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
  --pause PAUSE, -p PAUSE
                        webcam pause
  --auto_frameNum AUTO_FRAMENUM, -afn AUTO_FRAMENUM
                        auto save number of frames
  --logName LOGNAME, -ln LOGNAME
                        log Save Name
  --logMode LOGMODE, -lm LOGMODE
                        log Save Mode