Skip to main content

webcam opencv script

Project description

Simple Icons

OpenCV Webcam Script

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

PyPi Version Docker License

更新走势


安装教程


:white_check_mark: 方法一: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脚本

:white_check_mark: 方法二:pip 快速安装(API版)

  • 第一步:创建ow虚拟环境,参见方法一
  • 第二步:执行pip指令
pip install opencv-webcam-script
  • 第三步:编写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)

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

sudo docker pull zengdockerdocker/opencv-webcam-script:v0.1 # 镜像拉取

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.1 # 进入容器
python3 opencv_webcam.py # 运行脚本程序

使用教程


:bulb: 常规调用

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

:bulb: 摄像头选择

# 多摄像头切换示例
python opencv_webcam.py -dev 1
python opencv_webcam.py -dev 2

:bulb: 设置退出键

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

:bulb: 自动保存帧

python opencv_webcam.py -isasf

:bulb: 每隔n帧保存一次帧

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

:bulb: 手动保存帧

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

:bulb: 自定义捕获键

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

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

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

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

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

:bulb: 设置保存路径

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

:bulb: 设置帧名前缀

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

:bulb: 设置帧格式

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

:bulb: 设置暂停键

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

:bulb: 设置保存帧数

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

:bulb: 指令查询

# 查询脚本参数
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_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]

OpenCV Webcam Script v0.2

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
  --is_handSaveFrame, -ishsf
                        is hand save frame
  --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
                        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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencv-webcam-script-0.2.0.tar.gz (21.6 kB view hashes)

Uploaded Source

Built Distribution

opencv_webcam_script-0.2.0-py3-none-any.whl (20.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page