From d2e9293edf3786056ad80bb9a4fb8dce7923b751 Mon Sep 17 00:00:00 2001 From: 13339479676 Date: Wed, 19 Jan 2022 09:35:53 +0800 Subject: [PATCH] readme v04 zip update --- README.md | 13 +++++++++++++ opencv_webcam.py | 7 ++++++- utils/compress.py | 10 +++++++--- v04.md | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 72d9f78..50e1661 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,19 @@ python opencv_webcam.py -lm w # 设置为覆盖模式 +#### :bulb: 视频帧压缩 + +```shell +# 常规压缩,默认test.zip(以自动版为例) +python opencv_webcam.py -isasf -ic +# 自定义压缩文件名称 +python opencv_webcam.py -isasf -ic -zn test02.zip +# 自动命名压缩文件 +python opencv_webcam.py -isasf -ic -isazn +``` + + + #### :bulb: 指令查询 diff --git a/opencv_webcam.py b/opencv_webcam.py index db722bc..c7aa581 100644 --- a/opencv_webcam.py +++ b/opencv_webcam.py @@ -65,6 +65,8 @@ def parse_args(known=False): # 压缩 parser.add_argument('--is_compress', '-ic', action='store_true', help='is compress file') + parser.add_argument('--is_autoZipName', '-isazn', + action='store_true', help='is auto zip name') parser.add_argument('--zipName', '-zn', default="test.zip", type=str, help='zip save name') args = parser.parse_known_args()[0] if known else parser.parse_args() @@ -92,6 +94,7 @@ def webcam_opencv(device_index="0", logName="test.log", logMode="a", is_compress=False, + is_autoZipName=False, zipName="test.zip"): keyList = [quit_key, frame_capKey, pause_key] # 快捷键列表 @@ -186,7 +189,7 @@ def webcam_opencv(device_index="0", # ------------------压缩文件------------------ if (is_compress): - webcam_zip(f'{ROOT_PATH}/{zipName}', frame_savePath) # 自定义压缩文件名称 + webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath) # 自定义压缩文件名称 def main(args): @@ -214,6 +217,7 @@ def main(args): # 压缩 is_compress = args.is_compress + is_autoZipName = args.is_autoZipName zipName = args.zipName argsYaml(args) # 脚本参数 @@ -239,6 +243,7 @@ def main(args): logName, logMode, is_compress, + is_autoZipName, zipName) diff --git a/utils/compress.py b/utils/compress.py index a95db06..f869095 100644 --- a/utils/compress.py +++ b/utils/compress.py @@ -18,10 +18,14 @@ def is_zipFile(zipName): # zip压缩 -def webcam_zip(zipName, preZipFilePath): - is_zipFile(zipName) +def webcam_zip(is_autoZipName, zipName, preZipFilePath): + if (is_autoZipName): + auto_zipName = str(preZipFilePath).split('/')[-1] + zip_file = zipfile.ZipFile(f'{auto_zipName}.zip', 'a') - zip_file = zipfile.ZipFile(zipName, 'a') + else: + is_zipFile(zipName) + zip_file = zipfile.ZipFile(zipName, 'a') # ----------压缩开始---------- file_list = os.listdir(preZipFilePath) diff --git a/v04.md b/v04.md index ea3d4c1..cd8474d 100644 --- a/v04.md +++ b/v04.md @@ -10,6 +10,7 @@ - 加入docker vim编辑器 - 加入视频帧压缩功能 - 加入自定义压缩文件名称 +- 加入自动命名压缩文件名称 ### BUG修复