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