Commit 5c2dfcd4 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

plot: make the module more customizable

parent 2a9d1b22
...@@ -84,23 +84,33 @@ namespace cv ...@@ -84,23 +84,33 @@ namespace cv
CV_WRAP virtual void setPlotGridColor(Scalar _plotGridColor) = 0; CV_WRAP virtual void setPlotGridColor(Scalar _plotGridColor) = 0;
CV_WRAP virtual void setPlotTextColor(Scalar _plotTextColor) = 0; CV_WRAP virtual void setPlotTextColor(Scalar _plotTextColor) = 0;
CV_WRAP virtual void setPlotSize(int _plotSizeWidth, int _plotSizeHeight) = 0; CV_WRAP virtual void setPlotSize(int _plotSizeWidth, int _plotSizeHeight) = 0;
CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0;
CV_WRAP virtual void setShowText(bool needShowText) = 0;
CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0;
/**
* @brief Sets the index of a point which coordinates will be printed on the top left corner of the plot (if ShowText flag is true).
*
* @param pointIdx index of the required point in data array.
*/
CV_WRAP virtual void setPointIdxToPrint(int pointIdx) = 0;
CV_WRAP virtual void render(OutputArray _plotResult) = 0; CV_WRAP virtual void render(OutputArray _plotResult) = 0;
};
/** /**
* @brief Creates Plot2d object * @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 data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values
* will be equal to indexes of correspondind elements in data matrix. * will be equal to indexes of correspondind elements in data matrix.
*/ */
CV_EXPORTS_W Ptr<Plot2d> createPlot2d(InputArray data); CV_WRAP static Ptr<Plot2d> create(InputArray data);
/**
* @brief Creates Plot2d object /**
* * @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 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.
CV_EXPORTS_W Ptr<Plot2d> createPlot2d(InputArray dataX, InputArray dataY); */
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY);
};
//! @} //! @}
} }
} }
......
...@@ -168,7 +168,26 @@ namespace cv ...@@ -168,7 +168,26 @@ namespace cv
else else
plotSizeHeight = 300; plotSizeHeight = 300;
} }
void setShowGrid(bool _needShowGrid)
{
needShowGrid = _needShowGrid;
}
void setShowText(bool _needShowText)
{
needShowText = _needShowText;
}
void setGridLinesNumber(int _gridLinesNumber)
{
if(_gridLinesNumber <= 0)
_gridLinesNumber = 1;
gridLinesNumber = _gridLinesNumber;
}
void setPointIdxToPrint(int _cursorPos)
{
if(_cursorPos >= plotDataX.rows || _cursorPos < 0)
_cursorPos = plotDataX.rows - 1;
cursorPos = _cursorPos;
}
//render the plotResult to a Mat //render the plotResult to a Mat
void render(OutputArray _plotResult) void render(OutputArray _plotResult)
{ {
...@@ -189,8 +208,8 @@ namespace cv ...@@ -189,8 +208,8 @@ namespace cv
int ImageXzero = (int)InterpXdataFindZero.at<double>(NumVecElements,0); int ImageXzero = (int)InterpXdataFindZero.at<double>(NumVecElements,0);
int ImageYzero = (int)InterpYdataFindZero.at<double>(NumVecElements,0); int ImageYzero = (int)InterpYdataFindZero.at<double>(NumVecElements,0);
double CurrentX = plotDataX.at<double>(NumVecElements-1,0); double CurrentX = plotDataX.at<double>(cursorPos,0);
double CurrentY = plotDataY.at<double>(NumVecElements-1,0); double CurrentY = plotDataY.at<double>(cursorPos,0);
drawAxis(ImageXzero,ImageYzero, CurrentX, CurrentY, plotAxisColor, plotGridColor); drawAxis(ImageXzero,ImageYzero, CurrentX, CurrentY, plotAxisColor, plotGridColor);
...@@ -245,6 +264,10 @@ namespace cv ...@@ -245,6 +264,10 @@ namespace cv
double plotMinY_plusZero; double plotMinY_plusZero;
double plotMaxY_plusZero; double plotMaxY_plusZero;
int plotLineWidth; int plotLineWidth;
bool needShowGrid;
bool needShowText;
int gridLinesNumber;
int cursorPos;
//colors of each plot element //colors of each plot element
Scalar plotLineColor; Scalar plotLineColor;
...@@ -319,22 +342,30 @@ namespace cv ...@@ -319,22 +342,30 @@ namespace cv
setPlotBackgroundColor(Scalar(0, 0, 0)); setPlotBackgroundColor(Scalar(0, 0, 0));
setPlotLineColor(Scalar(0, 255, 255)); setPlotLineColor(Scalar(0, 255, 255));
setPlotTextColor(Scalar(255, 255, 255)); setPlotTextColor(Scalar(255, 255, 255));
setShowGrid(true);
setShowText(true);
setGridLinesNumber(10);
setPointIdxToPrint(-1);
} }
void drawAxis(int ImageXzero, int ImageYzero, double CurrentX, double CurrentY, Scalar axisColor, Scalar gridColor) void drawAxis(int ImageXzero, int ImageYzero, double CurrentX, double CurrentY, Scalar axisColor, Scalar gridColor)
{ {
drawValuesAsText(0, ImageXzero, ImageYzero, 10, 20); if(needShowText)
drawValuesAsText(0, ImageXzero, ImageYzero, -20, 20); {
drawValuesAsText(0, ImageXzero, ImageYzero, 10, -10); drawValuesAsText(0, ImageXzero, ImageYzero, 10, 20);
drawValuesAsText(0, ImageXzero, ImageYzero, -20, -10); drawValuesAsText(0, ImageXzero, ImageYzero, -20, 20);
drawValuesAsText("X = %g",CurrentX, 0, 0, 40, 20); drawValuesAsText(0, ImageXzero, ImageYzero, 10, -10);
drawValuesAsText("Y = %g",CurrentY, 0, 20, 40, 20); drawValuesAsText(0, ImageXzero, ImageYzero, -20, -10);
drawValuesAsText((format("X_%d = ", cursorPos) + "%g").c_str(), CurrentX, 0, 0, 40, 20);
drawValuesAsText((format("Y_%d = ", cursorPos) + "%g").c_str(), CurrentY, 0, 20, 40, 20);
}
//Horizontal X axis and equispaced horizontal lines //Horizontal X axis and equispaced horizontal lines
int LineSpace = 50; int LineSpace = cvRound(plotSizeHeight / (float)gridLinesNumber);
int TraceSize = 5; int TraceSize = 5;
drawLine(0, plotSizeWidth, ImageYzero, ImageYzero, axisColor); drawLine(0, plotSizeWidth, ImageYzero, ImageYzero, axisColor);
if(needShowGrid)
for(int i=-plotSizeHeight; i<plotSizeHeight; i=i+LineSpace){ for(int i=-plotSizeHeight; i<plotSizeHeight; i=i+LineSpace){
if(i!=0){ if(i!=0){
...@@ -349,7 +380,9 @@ namespace cv ...@@ -349,7 +380,9 @@ namespace cv
//Vertical Y axis //Vertical Y axis
drawLine(ImageXzero, ImageXzero, 0, plotSizeHeight, axisColor); drawLine(ImageXzero, ImageXzero, 0, plotSizeHeight, axisColor);
LineSpace = cvRound(LineSpace * (float)plotSizeWidth / plotSizeHeight );
if(needShowGrid)
for(int i=-plotSizeWidth; i<plotSizeWidth; i=i+LineSpace){ for(int i=-plotSizeWidth; i<plotSizeWidth; i=i+LineSpace){
if(i!=0){ if(i!=0){
...@@ -420,13 +453,13 @@ namespace cv ...@@ -420,13 +453,13 @@ namespace cv
}; };
Ptr<Plot2d> createPlot2d(InputArray _plotData) Ptr<Plot2d> Plot2d::create(InputArray _plotData)
{ {
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData)); return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData));
} }
Ptr<Plot2d> createPlot2d(InputArray _plotDataX, InputArray _plotDataY) Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY)
{ {
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY)); return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY));
} }
......
...@@ -165,7 +165,7 @@ struct AlgoWrap ...@@ -165,7 +165,7 @@ struct AlgoWrap
void plotLTRC(Mat &img) const void plotLTRC(Mat &img) const
{ {
Ptr<plot::Plot2d> p_ = plot::createPlot2d(getLTRC()); Ptr<plot::Plot2d> p_ = plot::Plot2d::create(getLTRC());
p_->render(img); p_->render(img);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment