【Python脚本】正则提取两组x,y数据并绘图对比

本文通过读取并解析四组数据,展示了OpenCV(Open Source Computer Vision Library)和DSP(数字信号处理)在关键帧处理性能上的差异。通过CPM图,'x_compare'和'y_compare'分别对比了两个库在x坐标和y坐标的性能变化,有助于理解它们在实际应用中的优劣。
摘要由CSDN通过智能技术生成
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")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值