mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-18 08:44:11 +08:00
Update plot module (#1367)
* Update plot.hpp * update * plot_demo * remove_tabs * Update plot_demo.cpp * Update plot.hpp * Update plot.hpp
This commit is contained in:

committed by
Vadim Pisarevsky

parent
eef53c29eb
commit
97ea5bf97d
@@ -99,17 +99,19 @@ namespace cv
|
||||
* @brief Creates Plot2d object
|
||||
*
|
||||
* @param data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values
|
||||
* @param _invertOrientation true means the y axis is inverted
|
||||
* will be equal to indexes of correspondind elements in data matrix.
|
||||
*/
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray data);
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray data, bool _invertOrientation=false);
|
||||
|
||||
/**
|
||||
* @brief Creates Plot2d object
|
||||
*
|
||||
* @param dataX \f$1xN\f$ or \f$Nx1\f$ matrix \f$X\f$ values of points to plot.
|
||||
* @param dataY \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot.
|
||||
* @param _invertOrientation true means the y axis is inverted
|
||||
*/
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY);
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY, bool _invertOrientation=false);
|
||||
};
|
||||
//! @}
|
||||
}
|
||||
|
35
modules/plot/samples/plot_demo.cpp
Normal file
35
modules/plot/samples/plot_demo.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/plot.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
Mat data_x(1, 50, CV_64F);
|
||||
Mat data_y(1, 50, CV_64F);
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
data_x.at<double>(0, i) = (i - 25);
|
||||
data_y.at<double>(0, i) = (i - 25)*(i - 25)*(i - 25);
|
||||
}
|
||||
|
||||
std::cout << "data_x : " << data_x << std::endl;
|
||||
std::cout << "data_y : " << data_y << std::endl;
|
||||
|
||||
Mat plot_result;
|
||||
|
||||
Ptr<plot::Plot2d> plot = plot::Plot2d::create(data_x, data_y);
|
||||
plot->render(plot_result);
|
||||
|
||||
imshow("default orientation", plot_result);
|
||||
|
||||
plot = plot::Plot2d::create(data_x, data_y,true);
|
||||
plot->render(plot_result);
|
||||
|
||||
imshow("inverted orientation", plot_result);
|
||||
waitKey();
|
||||
|
||||
return 0;
|
||||
}
|
@@ -57,8 +57,9 @@ namespace cv
|
||||
{
|
||||
public:
|
||||
|
||||
Plot2dImpl(InputArray plotData)
|
||||
Plot2dImpl(InputArray plotData, bool _invertOrientation)
|
||||
{
|
||||
invertOrientation = _invertOrientation;
|
||||
Mat _plotData = plotData.getMat();
|
||||
//if the matrix is not Nx1 or 1xN
|
||||
if(_plotData.cols > 1 && _plotData.rows > 1)
|
||||
@@ -84,8 +85,9 @@ namespace cv
|
||||
|
||||
}
|
||||
|
||||
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_)
|
||||
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_, bool _invertOrientation)
|
||||
{
|
||||
invertOrientation = _invertOrientation;
|
||||
Mat _plotDataX = plotDataX_.getMat();
|
||||
Mat _plotDataY = plotDataY_.getMat();
|
||||
//f the matrix is not Nx1 or 1xN
|
||||
@@ -199,11 +201,15 @@ namespace cv
|
||||
int NumVecElements = plotDataX.rows;
|
||||
|
||||
Mat InterpXdata = linearInterpolation(plotMinX, plotMaxX, 0, plotSizeWidth, plotDataX);
|
||||
Mat InterpYdata = linearInterpolation(plotMinY, plotMaxY, 0, plotSizeHeight, plotDataY);
|
||||
Mat InterpYdata = invertOrientation ?
|
||||
linearInterpolation(plotMaxY, plotMinY, 0, plotSizeHeight, plotDataY) :
|
||||
linearInterpolation(plotMinY, plotMaxY, 0, plotSizeHeight, plotDataY);
|
||||
|
||||
//Find the zeros in image coordinates
|
||||
Mat InterpXdataFindZero = linearInterpolation(plotMinX_plusZero, plotMaxX_plusZero, 0, plotSizeWidth, plotDataX_plusZero);
|
||||
Mat InterpYdataFindZero = linearInterpolation(plotMinY_plusZero, plotMaxY_plusZero, 0, plotSizeHeight, plotDataY_plusZero);
|
||||
Mat InterpYdataFindZero = invertOrientation ?
|
||||
linearInterpolation(plotMaxY_plusZero, plotMinY_plusZero, 0, plotSizeHeight, plotDataY_plusZero) :
|
||||
linearInterpolation(plotMinY_plusZero, plotMaxY_plusZero, 0, plotSizeHeight, plotDataY_plusZero);
|
||||
|
||||
int ImageXzero = (int)InterpXdataFindZero.at<double>(NumVecElements,0);
|
||||
int ImageYzero = (int)InterpYdataFindZero.at<double>(NumVecElements,0);
|
||||
@@ -264,6 +270,7 @@ namespace cv
|
||||
double plotMinY_plusZero;
|
||||
double plotMaxY_plusZero;
|
||||
int plotLineWidth;
|
||||
bool invertOrientation;
|
||||
bool needShowGrid;
|
||||
bool needShowText;
|
||||
int gridLinesNumber;
|
||||
@@ -453,15 +460,15 @@ namespace cv
|
||||
|
||||
};
|
||||
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotData)
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotData, bool _invertOrientation)
|
||||
{
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData));
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData, _invertOrientation));
|
||||
|
||||
}
|
||||
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY)
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY, bool _invertOrientation)
|
||||
{
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY));
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY, _invertOrientation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user