import re
import matplotlib.pyplot as plt
import numpy as np
def withdraw_data(path, regex_str):
string = open(path, encoding="UTF-8").read()
# a = re.findall(r"FastDetect cost: (/d+\.?\d*)", string)
# a = re.findall(r"stage3: (\d+\.?\d*)", string)
a = re.findall(r"{}(\d+\.?\d*)".format(regex_str), string)
b = list(map(float, a))
return b
def draw_cpm_graph(a, b, title="untitle"):
c = []
for i in range(len(b)):
c.append(b[i] - a[i])
x = []
for i in range(len(b)):
x.append(i)
plt.figure()
plt.title(title)
plt.plot(x, c)
plt.axhline(y=0, ls=":", c="yellow")
plt.axhline(y=1, ls=":", c="red")
plt.axhline(y=-1, ls=":", c="red")
plt.show()
if __name__ == '__main__':
opencv_x = withdraw_data("E:/rb5/debug/opencv_lk_result_1.txt", "x : ")
opencv_y = withdraw_data("E:/rb5/debug/opencv_lk_result_1.txt", "y : ")
dsp_x = withdraw_data("E:/rb5/debug/dsp_lk_result_1.txt", "x : ")
dsp_y = withdraw_data("E:/rb5/debug/dsp_lk_result_1.txt", "y : ")
# print(dsp_x)
draw_cpm_graph(opencv_x, dsp_x, "x_compare")
draw_cpm_graph(opencv_y, dsp_y, "y_compare")
【Python脚本】正则提取两组x,y数据并绘图对比
最新推荐文章于 2023-06-21 11:34:47 发布
本文通过读取并解析四组数据,展示了OpenCV(Open Source Computer Vision Library)和DSP(数字信号处理)在关键帧处理性能上的差异。通过CPM图,'x_compare'和'y_compare'分别对比了两个库在x坐标和y坐标的性能变化,有助于理解它们在实际应用中的优劣。
摘要由CSDN通过智能技术生成