hot key judge

This commit is contained in:
13339479676 2022-01-04 13:57:49 +08:00
parent 1215bdc0a8
commit b141d48237
1 changed files with 22 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import argparse
import time
import glob
import os
import sys
from utils.ows_path import increment_path
@ -55,10 +56,11 @@ def frame_opt(frame, frame_savePath, frame_num, is_resizeFrame, resize_frame, re
# 判断图片质量范围
if (jpg_quality < 0 or jpg_quality > 100):
print(f'JPG质量系数超出范围无法保存')
return
sys.exit() # 结束程序
if (png_quality < 0 or png_quality > 9):
print(f'PNG质量系数超出范围无法保存')
return
sys.exit() # 结束程序
if (is_resizeFrame): # resize frame
w_resize = int(
@ -78,7 +80,8 @@ def frame_opt(frame, frame_savePath, frame_num, is_resizeFrame, resize_frame, re
[int(cv2.IMWRITE_PNG_COMPRESSION), png_quality])
else:
print(f'帧格式有问题!无法保存!')
return
sys.exit() # 结束程序
else:
if (frame_saveStyle == 'jpg'):
cv2.imwrite(
@ -90,16 +93,26 @@ def frame_opt(frame, frame_savePath, frame_num, is_resizeFrame, resize_frame, re
[int(cv2.IMWRITE_PNG_COMPRESSION), png_quality])
else:
print(f'帧格式有问题!无法保存!')
return
sys.exit() # 结束程序
# 判断快捷键是否冲突
def hotkey_judge(keyList):
for i in range(len(keyList)):
tmp_key = keyList[i] # 临时快捷键
for j in range(len(keyList[i+1:])):
if (tmp_key == keyList[i+1:][j]):
print(f'快捷键冲突! 程序结束!')
sys.exit() # 结束程序
# Webcam OpenCV
def webcam_opencv(device_index, quit_key, pause_key, is_autoSaveFrame, frame_saveDir, frame_nSave, auto_frameNum, is_handSaveFrame,
frame_capKey, is_resizeFrame, resize_frame, resizeRatio_frame, frame_namePrefix, frame_saveStyle,
jpg_quality, png_quality):
if (quit_key == frame_capKey): # 判断快捷键冲突
print(f'快捷键冲突! 程序结束!')
return
keyList = [quit_key, frame_capKey, pause_key] # 快捷键列表
hotkey_judge(keyList) # 快捷键冲突判断
s_time = time.time() # 起始时间
cap = cv2.VideoCapture(device_index) # 连接设备
@ -124,7 +137,8 @@ def webcam_opencv(device_index, quit_key, pause_key, is_autoSaveFrame, frame_sav
wait_key = cv2.waitKey(20) & 0xFF # 键盘监听
ret, frame = cap.read() # 捕获画面
frame_num += 1 # 帧计数
print(f'当前帧:第{frame_num}') # 输出信息
# print(f'当前帧:第{frame_num}帧') # 输出信息
print(f'帧ID{frame_num}') # 输出信息
cv2.imshow(ows_version, frame) # 显示画面
if (is_autoSaveFrame): # 自动保存