v05 plot update

This commit is contained in:
13339479676 2022-01-29 16:34:51 +08:00
parent 298a4cb64a
commit 937a50578a
2 changed files with 27 additions and 55 deletions

View File

@ -214,8 +214,9 @@ def webcam_opencv(device_index="0",
# ------------------创建chart------------------
is_fonts(f'{ROOT_PATH}/fonts') # 检查字体文件
date_list, time_list, frames_y = csv2list("./date_time_frames.csv") # 转换日期-帧数文件
createLineChart(frames_y, date_list, time_list) # 创建日期-帧数图
# date_list, time_list, frames_y = csv2list("./date_time_frames.csv") # 转换日期-帧数文件
# createLineChart(frames_y, date_list, time_list) # 创建日期-帧数图
csv2list("./date_time_frames.csv")
else: # 连接设备失败
print(f'摄像头连接异常!')

View File

@ -9,8 +9,7 @@ from matplotlib.ticker import MaxNLocator
import sys
import csv
import time
# from utils.time_format import time_format
from time_format import time_format
from utils.time_format import time_format
OWS_VERSION = 'OpenCV Webcam Script v0.5' # 版本号
@ -62,73 +61,45 @@ def createLineChart(frames_y, date_list, time_list):
plt.legend(prop=SimSun, fontsize=12, loc='best') # 图例
# 保存图像
plt.savefig(f'{ROOT_PATH}/date_frames_chart.png',
plt.savefig(f'{ROOT_PATH}/date_frames_chart_{date_list[0]}.png',
dpi=300, bbox_inches='tight')
# -----------作图结束-----------
chart_endTime = time.time() # 作图开始时间
chart_totalTime = chart_endTime - chart_startTime # 作图用时
print(
f'日期-帧数图创建成功!用时:{time_format(chart_totalTime)},已保存在{ROOT_PATH}/date_frames_chart.png')
f'日期-帧数图创建成功!用时:{time_format(chart_totalTime)},已保存在{ROOT_PATH}/date_frames_chart{date_list[0]}.png')
# csv2list
def csv2list(csv_path):
f = open(csv_path, 'r') # 读取csv
f_list = csv.reader(f) # 转成csv
f_list = list(csv.reader(f)) # csv2list
d_list = [] # 日期列表
t_list = [] # 时间列表
frames_list = [] # 时间列表
for item in f_list:
d_list.append(item[0].split(' ')[0])
t_list.append(item[0].split(' ')[1])
frames_list.append(int(item[1]))
tmp_date = f_list[0][0].split(' ')[0]
for i in range(len(f_list)):
date_item = f_list[i][0].split(' ')[0] # 日期
time_item = f_list[i][0].split(' ')[1] # 时间
return d_list, t_list, frames_list
if (tmp_date != date_item):
createLineChart(frames_list, d_list, t_list) # 创建日期-帧数图
tmp_date = date_item # 替换
# 清空列表
d_list = []
t_list = []
frames_list = []
d_list.append(date_item) # 日期
t_list.append(time_item) # 时间
frames_list.append(int(f_list[i][1])) # 帧数
if (i == len(f_list)-1):
# 最后一组
createLineChart(frames_list, d_list, t_list)
def index_date(date_list):
tmp_date = date_list[0] # 首个日期
i_d_list = []
# i_d_list.append([0, tmp_date])
i_d_list.append(0)
for i in range(len(date_list)):
if (tmp_date != date_list[i]):
# i_d_list.append([i, date_list[i]])
i_d_list.append(i)
tmp_date = date_list[i]
print(i_d_list)
return i_d_list
# def date_time_frames_split(csv_path="../date_time_frames.csv"):
# f = open(csv_path, 'r') # 读取csv
# f_list = csv.reader(f) # 转成csv
# for item in f_list:
# print(item)
# d_list = [] # 日期列表
# t_list = [] # 时间列表
# frames_list = [] # 时间列表
# tmp_date = date_list[0] # 首个日期
# i_d_list = []
# i_d_list.append([0, tmp_date])
# for i in range(len(date_list)):
# if (tmp_date != date_list[i]):
# i_d_list.append([i, date_list[i]])
# tmp_date = date_list[i]
# print(i_d_list)
# return i_d_list
if __name__ == '__main__':
date_list, time_list, frames_list = csv2list("../date_time_frames.csv")
index_date(date_list)
# createLineChart(frames_list, date_list, time_list) # 创建日期-帧数图
# date_time_frames_split()
# if __name__ == '__main__':
# csv2list("../date_time_frames.csv")