webcam compress update 02
This commit is contained in:
parent
6ec35cbf11
commit
7ef5f7abe7
|
@ -263,13 +263,13 @@ python opencv_webcam.py -lm w # 设置为覆盖模式
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# 常规压缩,默认test.zip(以自动版为例)
|
# 常规压缩,默认test.zip(以自动版为例)
|
||||||
python opencv_webcam.py -isasf -ic
|
python opencv_webcam.py -isasf -isc
|
||||||
# 自定义压缩文件名称
|
# 自定义压缩文件名称
|
||||||
python opencv_webcam.py -isasf -ic -zn test02.zip
|
python opencv_webcam.py -isasf -isc -zn test02.zip
|
||||||
# 自动命名压缩文件
|
# 自动命名压缩文件
|
||||||
python opencv_webcam.py -isasf -ic -isazn
|
python opencv_webcam.py -isasf -isc -isazn
|
||||||
# 自定义压缩模式,默认为写覆盖
|
# 自定义压缩模式,默认为写覆盖
|
||||||
python opencv_webcam.py -isasf -ic -zn test03.zip -zm a # 追加模式
|
python opencv_webcam.py -isasf -isc -zn test03.zip -zm a # 追加模式
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ from utils.hotkey import hotkey_judge
|
||||||
from utils.frame_opt import frame_opt
|
from utils.frame_opt import frame_opt
|
||||||
from utils.log import is_logSuffix, log_management
|
from utils.log import is_logSuffix, log_management
|
||||||
from utils.args_yaml import argsYaml
|
from utils.args_yaml import argsYaml
|
||||||
from utils.compress import webcam_zip, webcam_tar, webcam_compress
|
from utils.compress import webcam_zip, webcam_tar, webcam_compress, is_compressFile
|
||||||
|
|
||||||
ROOT_PATH = sys.path[0] # 项目根目录
|
ROOT_PATH = sys.path[0] # 项目根目录
|
||||||
|
|
||||||
|
@ -63,14 +63,16 @@ def parse_args(known=False):
|
||||||
parser.add_argument('--logMode', '-lm',
|
parser.add_argument('--logMode', '-lm',
|
||||||
default="a", type=str, help='log write mode')
|
default="a", type=str, help='log write mode')
|
||||||
# 压缩
|
# 压缩
|
||||||
parser.add_argument('--is_compress', '-ic',
|
parser.add_argument('--is_compress', '-isc',
|
||||||
action='store_true', help='is compress file')
|
action='store_true', help='is compress file')
|
||||||
parser.add_argument('--is_autoZipName', '-isazn',
|
parser.add_argument('--compressStyle', '-cs',
|
||||||
action='store_true', help='is auto zip name')
|
default="zip", type=str, help='compress style')
|
||||||
parser.add_argument('--zipName', '-zn',
|
parser.add_argument('--is_autoCompressName', '-isacn',
|
||||||
default="test.zip", type=str, help='zip save name')
|
action='store_true', help='is auto compress name')
|
||||||
parser.add_argument('--zipMode', '-zm',
|
parser.add_argument('--compressName', '-cn',
|
||||||
default="w", type=str, help='zip save mode')
|
default="test.zip", type=str, help='compress save name')
|
||||||
|
parser.add_argument('--compressMode', '-cm',
|
||||||
|
default="w", type=str, help='compress save mode')
|
||||||
args = parser.parse_known_args()[0] if known else parser.parse_args()
|
args = parser.parse_known_args()[0] if known else parser.parse_args()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -96,9 +98,10 @@ def webcam_opencv(device_index="0",
|
||||||
logName="test.log",
|
logName="test.log",
|
||||||
logMode="a",
|
logMode="a",
|
||||||
is_compress=False,
|
is_compress=False,
|
||||||
is_autoZipName=False,
|
compressStyle="zip",
|
||||||
zipName="test.zip",
|
is_autoCompressName=False,
|
||||||
zipMode="w"):
|
compressName="test.zip",
|
||||||
|
compressMode="w"):
|
||||||
|
|
||||||
keyList = [quit_key, frame_capKey, pause_key] # 快捷键列表
|
keyList = [quit_key, frame_capKey, pause_key] # 快捷键列表
|
||||||
hotkey_judge(keyList) # 快捷键冲突判断
|
hotkey_judge(keyList) # 快捷键冲突判断
|
||||||
|
@ -108,6 +111,8 @@ def webcam_opencv(device_index="0",
|
||||||
logTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 日志时间
|
logTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 日志时间
|
||||||
log_management(f'{logTime}\n', logName, logMode) # 记录日志时间
|
log_management(f'{logTime}\n', logName, logMode) # 记录日志时间
|
||||||
|
|
||||||
|
is_compressFile(compressName) # 检测压缩文件格式
|
||||||
|
|
||||||
time_list = [1, 60, 3600] # 时间参数列表
|
time_list = [1, 60, 3600] # 时间参数列表
|
||||||
|
|
||||||
# ------------------程序开始------------------
|
# ------------------程序开始------------------
|
||||||
|
@ -194,7 +199,9 @@ def webcam_opencv(device_index="0",
|
||||||
if (is_compress and (is_autoSaveFrame or is_handSaveFrame)):
|
if (is_compress and (is_autoSaveFrame or is_handSaveFrame)):
|
||||||
# 自定义压缩文件名称
|
# 自定义压缩文件名称
|
||||||
# webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath, zipMode)
|
# webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath, zipMode)
|
||||||
webcam_tar(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath)
|
# webcam_tar(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath)
|
||||||
|
webcam_compress(compressStyle, is_autoCompressName,
|
||||||
|
f'{ROOT_PATH}/{compressName}', frame_savePath, compressMode)
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
@ -222,9 +229,10 @@ def main(args):
|
||||||
|
|
||||||
# 压缩
|
# 压缩
|
||||||
is_compress = args.is_compress
|
is_compress = args.is_compress
|
||||||
is_autoZipName = args.is_autoZipName
|
compressStyle = args.compressStyle
|
||||||
zipName = args.zipName
|
is_autoCompressName = args.is_autoCompressName
|
||||||
zipMode = args.zipMode
|
compressName = args.compressName
|
||||||
|
compressMode = args.compressMode
|
||||||
|
|
||||||
argsYaml(args) # 脚本参数
|
argsYaml(args) # 脚本参数
|
||||||
|
|
||||||
|
@ -249,9 +257,10 @@ def main(args):
|
||||||
logName,
|
logName,
|
||||||
logMode,
|
logMode,
|
||||||
is_compress,
|
is_compress,
|
||||||
is_autoZipName,
|
compressStyle,
|
||||||
zipName,
|
is_autoCompressName,
|
||||||
zipMode)
|
compressName,
|
||||||
|
compressMode)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -28,8 +28,9 @@ def is_tarFile(tarName):
|
||||||
|
|
||||||
# 判断压缩文件名称
|
# 判断压缩文件名称
|
||||||
def is_compressFile(compressName):
|
def is_compressFile(compressName):
|
||||||
|
compressList = ['zip', 'tar']
|
||||||
compressNameSuffix = compressName.split('.')[-1]
|
compressNameSuffix = compressName.split('.')[-1]
|
||||||
if compressNameSuffix != "zip" or "tar":
|
if compressNameSuffix not in compressList:
|
||||||
print(f'{compressName}:格式不正确!程序退出!')
|
print(f'{compressName}:格式不正确!程序退出!')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
@ -85,13 +86,17 @@ def webcam_compress(compressStyle, is_autoCompressName, compressName, preCompres
|
||||||
# 自动命名
|
# 自动命名
|
||||||
compressNameTmp = str(preCompressFilePath).split('/')[-1]
|
compressNameTmp = str(preCompressFilePath).split('/')[-1]
|
||||||
compressName = f'{ROOT_PATH}/{compressNameTmp}.{compressStyle}'
|
compressName = f'{ROOT_PATH}/{compressNameTmp}.{compressStyle}'
|
||||||
|
else:
|
||||||
|
is_compressFile(compressName)
|
||||||
|
|
||||||
file_list = os.listdir(preCompressFilePath) # 获取目录下的文件名称
|
file_list = os.listdir(preCompressFilePath) # 获取目录下的文件名称
|
||||||
|
|
||||||
if (compressStyle == "zip"):
|
if (compressStyle == "zip"):
|
||||||
|
is_zipFile(compressName)
|
||||||
# 实例化zipfile对象
|
# 实例化zipfile对象
|
||||||
compress_file = zipfile.ZipFile(compressName, compressMode)
|
compress_file = zipfile.ZipFile(compressName, compressMode)
|
||||||
if (compressStyle == "tar"):
|
if (compressStyle == "tar"):
|
||||||
|
is_tarFile(compressName)
|
||||||
# 实例化tarfile对象
|
# 实例化tarfile对象
|
||||||
compress_file = tarfile.open(compressName, compressMode)
|
compress_file = tarfile.open(compressName, compressMode)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue