Python 视频跟踪下蹲误报清除
猜想:下蹲动作矩形框尺寸变化远小于进门动作的矩形框尺寸变化
代码功能:输出变化比例,验证猜想
import json
import os
path = R''
def get_json_by_filename(json_file_path):
"""
从json文件里提取rect字段
"""
with open(json_file_path) as f:
json_data = json.load(f)
return json_data["rect"]
def reset(value):
value = float(0)
return value
def updateh1(filelist,n):
if filelist[3] <= 0.5 and filelist[3] > n:
return filelist[3]
else:
return n
def updateh2(filelist,n):
if filelist[3] > n:
return filelist[3]
else:
return n
def updates1(filelist,n,m):
if filelist[3] <= 0.5 and filelist[3] > n:
a = (filelist[3]-filelist[1])*(filelist[2]-filelist[0])
return a
else:
return m
def updates2(filelist,n,m):
if filelist[3] > n:
a = (filelist[3]-filelist[1])*(filelist[2]-filelist[0])
return a
else:
return m
def iter_files(rootDir):
#遍历根目录
json_data = {}
test = []
h1max = float(0)
h2max = float(0)
s1 = float(0)
s2 = float(0)
for root,dirs,files in os.walk(rootDir):
for file in files:
file_name = os.path.join(root,file)
file_rfind = file_name.rfind('.')
f = file_name[file_rfind + 1:]
if f == 'json':
json_data[file] = get_json_by_filename(file_name)
if test != []:
test_rfind = test.rfind('\\')
file_rfind1 = file_name.rfind('\\')
t = test[:test_rfind]
f1 = file_name[:file_rfind1]
if t != f1:
if h2max > 0.5:
print(file_name)
if s1 != 0:
print(s2/s1)
#输出面积比,小于一定值时即为下蹲误报
h1max = reset(h1max)
h2max = reset(h2max)
s1 = reset(s1)
s2 = reset(s2)
test = file_name
s1 = updates1(json_data[file],h1max,s1)
s2 = updates2(json_data[file],h2max,s2)
h1max = updateh1(json_data[file],h1max)
h2max = updateh2(json_data[file],h2max)
iter_files(path)