diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..a163ee2 --- /dev/null +++ b/README.en.md @@ -0,0 +1,429 @@ +[中文简体](./README.md)|English +

+ +Simple Icons + +

+ Webcam program based on OpenCV, suitable for real-time video frame acquisition, computer vision data collection, etc. +

+

+ It has the characteristics of convenient installation, simple operation and cross-platform. +

+

+

+code check +PyPi +Releases Version +Docker +Jupyter +License +

+ + + + +

🚀Update Trend

+ +- `2022-01-24` **⚡ [opencv-webcam-script v0.4 release](https://gitee.com/CV_Lab/opencv_webcam/releases/v0.4) officially launched** +- `2022-01-24` **⚡ [opencv-webcam-script v0.4 docker version](https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script) officially launched** +- `2022-01-24` **⚡ [opencv-webcam-script v0.4.0 PyPi version](https://pypi.org/project/opencv-webcam-script/0.4.0/)officially launched** +- `2022-01-24` **⚡ [opencv-webcam-script v0.4 Jupyter version](https://gitee.com/CV_Lab/opencv_webcam/blob/master/tutorial/ows_jupyter.ipynb)officially launched** +- ⚡ [opencv-webcam-script v0.3](./v_change/v03_change.md) +- ⚡ [opencv-webcam-script v0.2](./v_change/v02_change.md) +- ⚡ [opencv-webcam-script v0.1](./v_change/v01_change.md) + + + +

💡Project Structure

+ +``` +. +├── opencv_webcam # 项目名称 +│ ├── utils # 工具包 +│ │ ├── args_yaml.py # 指令管理 +│ │ ├── compress.py # 压缩管理 +│ │ ├── frame_opt.py # 帧保存管理 +│ │ ├── hotkey.py # 热键管理 +│ │ ├── __init__.py # 工具包初始化 +│ │ ├── log.py # 日志管理 +│ │ ├── ows_path.py # 保存路径管理 +│ │ └── time_format.py # 时间格式化 +│ ├── v_change # 版本变更 +│ │ ├── v01_change.md # v0.1版本变更 +│ │ ├── v02_change.md # v0.2版本变更 +│ │ └── v03_change.md # v0.3版本变更 +│ ├── tutorial # ows教程 +│ │ ├── ows_pypi.md # ows pypi版教程 +│ │ ├── ows_docker.md # ows docker版教程 +│ │ └── ows_jupyter.md # ows Jupyter版教程 +│ ├── codeCheck.md # 代码检查 +│ ├── Dockerfile # docker构建文件 +│ ├── __init__.py # 项目初始化 +│ ├── LICENSE # 项目许可 +│ ├── opencv_webcam.py # 脚本主运行文件 +│ ├── README.md # 项目说明 +│ └── requirements.txt # 脚本依赖包 +``` + + + +

🔥Installation Tutorial

+ +### ✅ Method 1: Linux Shell Installation (Development Edition) + +- Step 1: Clone the project + +```shell +git clone https://gitee.com/CV_Lab/opencv_webcam.git # clone project +``` + +- Step 2: Create a virtual environment + +```shell +# Create a conda virtual environment, taking python 3.8 as an example +conda create -n ows python==3.8 # The virtual environment name is ows +conda activate ows # Activate the virtual environment +``` + +- Step 3: Install the script + +```shell +pip install -r ./requirements.txt -U # Install OpenCV Webcam Script +``` + +- Steps 2 and 3 can also be performed via `setup.sh` + +```shell +bash ./setup.sh +``` + + + +### ✅ Method 2: pip quick installation (PyPi version) + +#### 🔥 [opencv-webcam-script PyPi version detailed tutorial](./tutorial/ows_pypi.md) + +#### 🔑 Easy Tutorial + +- Step 1: Create an ows virtual environment, see Method 1 +- Step 2: Execute the pip command + +```shell +pip install opencv-webcam-script==0.4.0 +``` + +- Step 3: Write a python program + +```python +from opencv_webcam.opencv_webcam import webcam_opencv +# Example of a few functions +webcam_opencv() # regular call +webcam_opencv(is_autoSaveFrame=True) # Auto save frames +webcam_opencv(is_autoSaveFrame=True, is_compress=True) # compressed frame +``` + + + +### ✅ Method 3: docker image installation (docker version) + +#### 🔥 [opencv-webcam-script docker version detailed tutorial](./tutorial/ows_docker.md) + +#### 🔑 Easy Tutorial + +- 第一步:下载镜像 + +```shell +sudo docker pull zengdockerdocker/opencv-webcam-script:v0.4 # 镜像拉取 +``` + +- 第二步:创建容器 + +```shell +xhost +local:root # 允许root用户访问正在运行的X服务器(重要) +sudo docker run --name=ows --ipc=host -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY --device=/dev/video0:/dev/video0 zengdockerdocker/opencv-webcam-script:v0.4 # 创建名称为ows的容器 +``` + +- 第三步:运行程序 + +```shell +python3 opencv_webcam.py # 运行脚本程序 +python3 opencv_webcam.py -isasf # 自动保存帧 + +# 获取docker帧数据到本机 +sudo docker cp 容器名称:容器目录 本机宿主目录 +sudo docker cp ows:/usr/src/app/WebcamFrame /home/用户名 # 举例 +``` + +### ✅ Method 4: Jupyter installation (Jupyter version) + +#### 🔥 [opencv-webcam-script Jupyter version detailed tutorial](./tutorial/ows_jupyter.ipynb) + +#### 🔑 Easy Tutorial + +- 第一步:安装 + +```shell +# 首先手动创建虚拟环境 +# conda create -n ows python==3.8 # 虚拟环境名称为ows +# conda activate ows # 激活虚拟环境 +!git clone https://gitee.com/CV_Lab/opencv_webcam.git # 克隆 +%cd opencv_webcam +%pip install -qr requirements.txt -U # 安装 +``` + +- 第二步:运行 + +```shell +!python opencv_webcam.py # 默认按q键退出 +!python opencv_webcam.py -isasf # 视频帧自动保存 +``` + +**Note: Jupyter version of ows program can run unit instructions through `Ctrl+Enter`** + + + +

⚡Usage

+ +#### 💡 常规调用 + +```shell +# 默认按q键退出 +python opencv_webcam.py +``` + + + +#### 💡 设备选择 + +```shell +# 多摄像头切换示例,默认为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 +``` + + + +#### 💡 设置退出键 + +```shell +# 默认按q键退出 +python opencv_webcam.py -q z # 设置z键退出 +python opencv_webcam.py -q k # 设置k键退出 +``` + + + +#### 💡 自动保存帧 + +```shell +python opencv_webcam.py -isasf +``` + + + +#### 💡 每隔n帧保存一次帧 + +```shell +# 每隔10帧保存一次帧 +python opencv_webcam.py -isasf -fns 10 +``` + + + +#### 💡 手动保存帧 + +```shell +# 默认按a键捕获一帧 +python opencv_webcam.py -ishsf +``` + + + +#### 💡 自定义捕获键 + +```shell +# 设置z键为捕获键,默认为a键 +python opencv_webcam.py -ishsf -fck z +``` + + + +#### 💡 重塑帧尺寸(自定义宽高) + +```shell +# 重塑宽度300 高度200 +python opencv_webcam.py -isasf -isrf -rf 300 200 # 自动版 +python opencv_webcam.py -ishsf -isrf -rf 300 200 # 手动版 +``` + + + +#### 💡 重塑帧尺寸(自定义宽高缩放比) + +```shell +# 宽高缩放比为0.5 +python opencv_webcam.py -isasf -isrf -rrf 0.5 # 自动版 +python opencv_webcam.py -ishsf -isrf -rrf 0.5 # 手动版 +``` + + + +#### 💡 自定义保存路径 + +```shell +# 设置保存路径,默认保存路径为./WebcamFrame +python opencv_webcam.py -fsd custom_dir -isasf # 以自动版为例 +``` + + + +#### 💡 自定义帧目录名称 + +```shell +# 设置帧目录名称,默认保存路径为frames +python opencv_webcam.py -fdn frames_custom -isasf # 以自动版为例 +``` + + + + +#### 💡 自定义帧名前缀 + +```shell +# 设置帧图片的前缀名称 +python opencv_webcam.py -isasf -fnp webcam +``` + + + +#### 💡 设置帧保存格式 + +```shell +# 设置JPG质量为100,默认为95 +python opencv_webcam.py -isasf -fss jpg -jq 100 +# 设置PNG质量为5,默认为3 +python opencv_webcam.py -isasf -fss png -jq 5 +``` + + + +#### 💡 设置暂停键 + +```shell +# 设置w键为暂停键,默认为p键 +python opencv_webcam.py -p w # 按任意键继续 +``` + + + +#### 💡 设置保存帧数 + +```shell +# 设置保存100帧 +python opencv_webcam.py -isasf -afn 100 +``` + + + +#### 💡 日志设置 + +```shell +# 日志文件默认保存在项目根目录,ows.log +python opencv_webcam.py +# 设置日志文件名称及类型,类型包括.log、.txt、.data +python opencv_webcam.py -ln ows02.txt +# 设置日志保存方式,,默认为追加模式 +python opencv_webcam.py -lm w # 设置为覆盖模式 +``` + + + +#### 💡 视频帧压缩 + +```shell +# 常规压缩,默认ows.zip(以自动版为例) +python opencv_webcam.py -isasf -isc +# 自定义压缩文件名称 +python opencv_webcam.py -isasf -isc -cn ows02 +# 自动命名压缩文件 +python opencv_webcam.py -isasf -isc -isacn +# 自定义压缩模式,默认为写覆盖 +python opencv_webcam.py -isasf -isc -cm a # 追加模式(a模式仅限zip) 注:该指令仅限v0.4 +python opencv_webcam.py -isasf -isc -cs tar -cm w:gz # tar压缩 +``` + + + +#### 💡 指令查询 + +```shell +# 查询脚本参数 +python opencv_webcam.py --help +``` + +
+指令查询结果 + +```shell +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] [--is_compress] [--compressStyle COMPRESSSTYLE] [--is_autoCompressName] + [--compressName COMPRESSNAME] [--compressMode COMPRESSMODE] + +OpenCV Webcam Script v0.4 + +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 write mode + --is_compress, -isc is compress file + --compressStyle COMPRESSSTYLE, -cs COMPRESSSTYLE + compress style + --is_autoCompressName, -isacn + is auto compress name + --compressName COMPRESSNAME, -cn COMPRESSNAME + compress save name + --compressMode COMPRESSMODE, -cm COMPRESSMODE + compress save mode, tar w:gz +``` + +
diff --git a/README.md b/README.md index 1164aa8..867f1ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -中文简体|[English](#) +中文简体|[English](./README.en.md)

Simple Icons diff --git a/utils/fonts_opt.py b/utils/fonts_opt.py index 461f03d..7fe582a 100644 --- a/utils/fonts_opt.py +++ b/utils/fonts_opt.py @@ -27,6 +27,7 @@ def is_fonts(fonts_dir): if (i not in f_list): # 字体不存在 fonts_flag = 1 + if (fonts_flag == 1): # 字体不存在 print(f'字体不存在,正在加载。。。') diff --git a/utils/plot.py b/utils/plot.py index 4f80a77..83612fa 100644 --- a/utils/plot.py +++ b/utils/plot.py @@ -13,14 +13,17 @@ SimSun = font_manager.FontProperties(fname="./fonts/SimSun.ttc", size=12) TimesNesRoman = font_manager.FontProperties( fname="./fonts/TimesNewRoman.ttf", size=12) + # 创建折线图 def createLineChart(x, y, today): - # x, y为两个list + today_list = today.split(' ') + today_date, today_time = today_list[0], today_list[1] + plt.plot(x, y, color='r', marker='o', label='时间点') # 线型 # plt.axis([0, 6, 0, 20]) - plt.title(f'OpenCV Webcam Script v0.5 {today}', + plt.title(f'OpenCV Webcam Script v0.5', fontproperties=TimesNesRoman) # 标题 - plt.xlabel(today, fontproperties=TimesNesRoman) # 横轴,时间 + plt.xlabel(today_date, fontproperties=TimesNesRoman) # 横轴,时间 plt.ylabel('帧数', fontproperties=SimSun) # 纵轴,帧数 plt.xticks(fontproperties=TimesNesRoman) # 横轴刻度 @@ -34,4 +37,13 @@ def createLineChart(x, y, today): if __name__ == '__main__': x = [1, 2, 3, 4] y = [1, 4, 9, 16] - createLineChart(x, y, "abc") + today01 = "2022-01-26 10:32:29" + today02 = "2022-01-26 10:32:51" + today03 = "2022-01-26 10:43:48" + today04 = "2022-01-26 10:43:56" + today05 = "2022-01-26 13:53:03" + # createLineChart(x, y, today) + + todayList = [today01, today02, today03, today04, today05] + print(todayList) +