Skip to content

Commit 3496ed5

Browse files
committed
Update plot module
1 parent b954189 commit 3496ed5

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

modules/plot/include/opencv2/plot.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ namespace cv
8787
CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0;
8888
CV_WRAP virtual void setShowText(bool needShowText) = 0;
8989
CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0;
90+
CV_WRAP virtual void setInvertOrientation(bool _invertOrientation) = 0;
9091
/**
9192
* @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).
9293
*
@@ -99,19 +100,17 @@ namespace cv
99100
* @brief Creates Plot2d object
100101
*
101102
* @param data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values
102-
* @param _invertOrientation true means the y axis is inverted
103103
* will be equal to indexes of correspondind elements in data matrix.
104104
*/
105-
CV_WRAP static Ptr<Plot2d> create(InputArray data, bool _invertOrientation=false);
105+
CV_WRAP static Ptr<Plot2d> create(InputArray data);
106106

107107
/**
108108
* @brief Creates Plot2d object
109109
*
110110
* @param dataX \f$1xN\f$ or \f$Nx1\f$ matrix \f$X\f$ values of points to plot.
111111
* @param dataY \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot.
112-
* @param _invertOrientation true means the y axis is inverted
113112
*/
114-
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY, bool _invertOrientation=false);
113+
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY);
115114
};
116115
//! @}
117116
}

modules/plot/samples/plot_demo.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,35 @@ using namespace cv;
66

77
int main()
88
{
9-
Mat data_x(1, 50, CV_64F);
10-
Mat data_y(1, 50, CV_64F);
9+
Mat data_x( 1, 51, CV_64F );
10+
Mat data_y( 1, 51, CV_64F );
1111

12-
for (int i = 0; i < 50; i++)
12+
for ( int i = 0; i < data_x.cols; i++ )
1313
{
14-
data_x.at<double>(0, i) = (i - 25);
15-
data_y.at<double>(0, i) = (i - 25)*(i - 25)*(i - 25);
14+
double x = ( i - data_x.cols / 2 );
15+
data_x.at<double>( 0, i ) = x;
16+
data_y.at<double>( 0, i ) = x * x * x;
1617
}
1718

1819
std::cout << "data_x : " << data_x << std::endl;
1920
std::cout << "data_y : " << data_y << std::endl;
2021

2122
Mat plot_result;
2223

23-
Ptr<plot::Plot2d> plot = plot::Plot2d::create(data_x, data_y);
24+
Ptr<plot::Plot2d> plot = plot::Plot2d::create( data_x, data_y );
2425
plot->render(plot_result);
2526

26-
imshow("default orientation", plot_result);
27+
imshow( "The plot rendered with default visualization options", plot_result );
2728

28-
plot = plot::Plot2d::create(data_x, data_y,true);
29-
plot->render(plot_result);
29+
plot->setShowText( false );
30+
plot->setShowGrid( false );
31+
plot->setPlotBackgroundColor( Scalar( 255, 200, 200 ) );
32+
plot->setPlotLineColor( Scalar( 255, 0, 0 ) );
33+
plot->setPlotLineWidth( 2 );
34+
plot->setInvertOrientation( true );
35+
plot->render( plot_result );
3036

31-
imshow("inverted orientation", plot_result);
37+
imshow( "The plot rendered with some of custom visualization options", plot_result );
3238
waitKey();
3339

3440
return 0;

modules/plot/src/plot.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ namespace cv
5757
{
5858
public:
5959

60-
Plot2dImpl(InputArray plotData, bool _invertOrientation)
60+
Plot2dImpl(InputArray plotData)
6161
{
62-
invertOrientation = _invertOrientation;
6362
Mat _plotData = plotData.getMat();
6463
//if the matrix is not Nx1 or 1xN
6564
if(_plotData.cols > 1 && _plotData.rows > 1)
@@ -85,9 +84,8 @@ namespace cv
8584

8685
}
8786

88-
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_, bool _invertOrientation)
87+
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_)
8988
{
90-
invertOrientation = _invertOrientation;
9189
Mat _plotDataX = plotDataX_.getMat();
9290
Mat _plotDataY = plotDataY_.getMat();
9391
//f the matrix is not Nx1 or 1xN
@@ -134,6 +132,10 @@ namespace cv
134132
{
135133
plotLineWidth = _plotLineWidth;
136134
}
135+
void setInvertOrientation(bool _invertOrientation)
136+
{
137+
invertOrientation = _invertOrientation;
138+
}
137139
void setNeedPlotLine(bool _needPlotLine)
138140
{
139141
needPlotLine = _needPlotLine;
@@ -270,7 +272,7 @@ namespace cv
270272
double plotMinY_plusZero;
271273
double plotMaxY_plusZero;
272274
int plotLineWidth;
273-
bool invertOrientation;
275+
bool invertOrientation;
274276
bool needShowGrid;
275277
bool needShowText;
276278
int gridLinesNumber;
@@ -314,6 +316,7 @@ namespace cv
314316
double MaxY_plusZero;
315317

316318
needPlotLine = true;
319+
invertOrientation = false;
317320

318321
//Obtain the minimum and maximum values of Xdata
319322
minMaxLoc(plotDataX,&MinX,&MaxX);
@@ -384,7 +387,6 @@ namespace cv
384387
}
385388
}
386389

387-
388390
//Vertical Y axis
389391
drawLine(ImageXzero, ImageXzero, 0, plotSizeHeight, axisColor);
390392
LineSpace = cvRound(LineSpace * (float)plotSizeWidth / plotSizeHeight );
@@ -413,7 +415,6 @@ namespace cv
413415

414416
if(Ydata.at<double>(i,0)<0)
415417
Ydata.at<double>(i,0)=0;
416-
417418
}
418419

419420
return Ydata;
@@ -457,18 +458,16 @@ namespace cv
457458

458459
line(plotResult, Axis_start, Axis_end, lineColor, plotLineWidth, 8, 0);
459460
}
460-
461461
};
462462

463-
Ptr<Plot2d> Plot2d::create(InputArray _plotData, bool _invertOrientation)
463+
Ptr<Plot2d> Plot2d::create(InputArray _plotData)
464464
{
465-
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData, _invertOrientation));
466-
465+
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData));
467466
}
468467

469-
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY, bool _invertOrientation)
468+
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY)
470469
{
471-
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY, _invertOrientation));
470+
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY));
472471
}
473472
}
474473
}

0 commit comments

Comments
 (0)