Python and Matlab绘制曲线图
2016-03-26 17:15
781 查看
前两天老师让标定一下视频中跟踪目标的真实位置(详见OpenCV记录鼠标左键点击位置),并与跟踪位置做一下对比。就是画一个误差图。刚开始用matlab画了一下,之前一直想学python,所以就用python又画一下。
下面是两者的效果:
MATLAB
python
很简单,下面直接上代码吧。
—————————————-MATLAB——————————————-
—————————————-Python——————————————-
注:程序运行需要保存于excel的数据,the whole project 详见:https://github.com/NodYoung/MATLAB-and-Python-read-excel-data-and-plot-the-line-graph
下面是两者的效果:
MATLAB
python
很简单,下面直接上代码吧。
—————————————-MATLAB——————————————-
%本文件用于计算图像追踪中真实点与跟踪点之间的误差 realdata = xlsread('realpoint.xlsx');%读取excel中的数据 trackingdata = xlsread('trackingpoint.xlsx'); realdatax = realdata(:, 1); realdatay = realdata(:, 2); trackingdatax = trackingdata(:, 1); trackingdatay = trackingdata(:, 2); xerror = abs(trackingdatax - realdatax); yerror = abs(trackingdatay - realdatay); distanterror = sqrt(xerror.^2 + yerror.^2); figure('numbertitle','off','name','The error of x direction','color','white'); plot(xerror);title('The error of x direction');xlabel('frames');ylabel('error(pixel)'); figure('numbertitle','off','name','The error of y direction','color','white'); plot(yerror);title('The error of y direction');xlabel('frames');ylabel('error(pixel)'); figure('numbertitle','off','name','The error of relative distance','color','white'); plot(distanterror);title('The error of relative distance');xlabel('frames');ylabel('error(pixel)');
—————————————-Python——————————————-
#编程环境:Anaconda3 + pycharm5 import xlrd import numpy as np import pylab as pl realdatafname = 'realpoint.xlsx' trackingdatafname = 'trackingpoint.xlsx' realdatabk = xlrd.open_workbook(realdatafname) # 获取xls文件 trackingdatabk = xlrd.open_workbook(trackingdatafname) # 获取xls文件 realdatash = realdatabk.sheet_by_name('Sheet1') #通过名称获取bk中的sheet trackingdatash = trackingdatabk.sheet_by_name('Sheet1') #通过名称获取bk中的sheet # nrows = realdatash.nrows # 获取行数 # ncols = realdatash.ncols # 获取列数 # print('nrows %d, ncols %d' % (nrows,ncols)) # cell_value = realdatash.cell_value(1, 1) # 获取单元格(1,1)的值 # print(cell_value) realdatax = np.array(realdatash.col_values(0)) # 获取第0列值的列表,并将其转换为array类型 realdatay = np.array(realdatash.col_values(1)) trackingdatax = np.array(trackingdatash.col_values(0)) # 获取第0列值的列表,并将其转换为array类型 trackingdatay = np.array(trackingdatash.col_values(1)) # print(realdatax) errorx = np.absolute(trackingdatax - realdatax) errory = np.absolute(trackingdatay - realdatay) errordistant = np.sqrt(errorx * errorx + errory * errory) pl.figure(1) pl.xlabel('frames') pl.ylabel('xerror(pixel)') pl.title('The error of x direction') pl.plot(errorx) # use pylab to plot x and y pl.figure(2) pl.xlabel('frames') pl.ylabel('yerror(pixel)') pl.title('The error of y direction') pl.plot(errory) # use pylab to plot x and y pl.figure(3) pl.xlabel('frames') pl.ylabel('xerror(pixel)') pl.title('The error of x direction') pl.plot(errordistant) # use pylab to plot x and y pl.show() # show the plot on the screen
注:程序运行需要保存于excel的数据,the whole project 详见:https://github.com/NodYoung/MATLAB-and-Python-read-excel-data-and-plot-the-line-graph
相关文章推荐
- 装载: Matlab 提取矩阵 某一行 或者 某一列 的方法
- MATLAB中字符串数组的创建和引用
- fluent ubuntu gnom matlab parallel
- MATLAB编译c++出错的解决办法(Error in compile (line 439) mex(args{:});)
- 图像质心分析:Matlab、质心法,高斯拟合法
- 关于循环读入多幅图片的方法(matlab和OpenCV)
- MATLAB/c++混合编程
- #怎样在Matlab中画柠檬
- Matlab---在多个axes之间切换
- 用Matlab画直方图
- 用Matlab画直方图
- matlab基本知识点3-单元数组与结构
- ubuntu 安装Matlab 解决显示中文乱码
- Apriori算法Matlab实现
- k-Mediods算法Matlab实现
- k-Means算法Matlab实现
- Matlab图像处理学习笔记(一):二值化、开操作、连通区域提取、重心、ROI
- Matlab-猜数游戏
- Hough变换检测椭圆 附带matlab与opencv代码
- 将matlab处理结果保存为图像文件