mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-15 03:38:39 +08:00
Update plot module
This commit is contained in:
@@ -87,6 +87,7 @@ namespace cv
|
||||
CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0;
|
||||
CV_WRAP virtual void setShowText(bool needShowText) = 0;
|
||||
CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0;
|
||||
CV_WRAP virtual void setInvertOrientation(bool _invertOrientation) = 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).
|
||||
*
|
||||
@@ -99,19 +100,17 @@ 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, bool _invertOrientation=false);
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray data);
|
||||
|
||||
/**
|
||||
* @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, bool _invertOrientation=false);
|
||||
CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY);
|
||||
};
|
||||
//! @}
|
||||
}
|
||||
|
@@ -6,13 +6,14 @@ using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
Mat data_x(1, 50, CV_64F);
|
||||
Mat data_y(1, 50, CV_64F);
|
||||
Mat data_x( 1, 51, CV_64F );
|
||||
Mat data_y( 1, 51, CV_64F );
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
for ( int i = 0; i < data_x.cols; i++ )
|
||||
{
|
||||
data_x.at<double>(0, i) = (i - 25);
|
||||
data_y.at<double>(0, i) = (i - 25)*(i - 25)*(i - 25);
|
||||
double x = ( i - data_x.cols / 2 );
|
||||
data_x.at<double>( 0, i ) = x;
|
||||
data_y.at<double>( 0, i ) = x * x * x;
|
||||
}
|
||||
|
||||
std::cout << "data_x : " << data_x << std::endl;
|
||||
@@ -20,15 +21,20 @@ int main()
|
||||
|
||||
Mat plot_result;
|
||||
|
||||
Ptr<plot::Plot2d> plot = plot::Plot2d::create(data_x, data_y);
|
||||
Ptr<plot::Plot2d> plot = plot::Plot2d::create( data_x, data_y );
|
||||
plot->render(plot_result);
|
||||
|
||||
imshow("default orientation", plot_result);
|
||||
imshow( "The plot rendered with default visualization options", plot_result );
|
||||
|
||||
plot = plot::Plot2d::create(data_x, data_y,true);
|
||||
plot->render(plot_result);
|
||||
plot->setShowText( false );
|
||||
plot->setShowGrid( false );
|
||||
plot->setPlotBackgroundColor( Scalar( 255, 200, 200 ) );
|
||||
plot->setPlotLineColor( Scalar( 255, 0, 0 ) );
|
||||
plot->setPlotLineWidth( 2 );
|
||||
plot->setInvertOrientation( true );
|
||||
plot->render( plot_result );
|
||||
|
||||
imshow("inverted orientation", plot_result);
|
||||
imshow( "The plot rendered with some of custom visualization options", plot_result );
|
||||
waitKey();
|
||||
|
||||
return 0;
|
||||
|
@@ -57,9 +57,8 @@ namespace cv
|
||||
{
|
||||
public:
|
||||
|
||||
Plot2dImpl(InputArray plotData, bool _invertOrientation)
|
||||
Plot2dImpl(InputArray plotData)
|
||||
{
|
||||
invertOrientation = _invertOrientation;
|
||||
Mat _plotData = plotData.getMat();
|
||||
//if the matrix is not Nx1 or 1xN
|
||||
if(_plotData.cols > 1 && _plotData.rows > 1)
|
||||
@@ -85,9 +84,8 @@ namespace cv
|
||||
|
||||
}
|
||||
|
||||
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_, bool _invertOrientation)
|
||||
Plot2dImpl(InputArray plotDataX_, InputArray plotDataY_)
|
||||
{
|
||||
invertOrientation = _invertOrientation;
|
||||
Mat _plotDataX = plotDataX_.getMat();
|
||||
Mat _plotDataY = plotDataY_.getMat();
|
||||
//f the matrix is not Nx1 or 1xN
|
||||
@@ -134,6 +132,10 @@ namespace cv
|
||||
{
|
||||
plotLineWidth = _plotLineWidth;
|
||||
}
|
||||
void setInvertOrientation(bool _invertOrientation)
|
||||
{
|
||||
invertOrientation = _invertOrientation;
|
||||
}
|
||||
void setNeedPlotLine(bool _needPlotLine)
|
||||
{
|
||||
needPlotLine = _needPlotLine;
|
||||
@@ -270,7 +272,7 @@ namespace cv
|
||||
double plotMinY_plusZero;
|
||||
double plotMaxY_plusZero;
|
||||
int plotLineWidth;
|
||||
bool invertOrientation;
|
||||
bool invertOrientation;
|
||||
bool needShowGrid;
|
||||
bool needShowText;
|
||||
int gridLinesNumber;
|
||||
@@ -314,6 +316,7 @@ namespace cv
|
||||
double MaxY_plusZero;
|
||||
|
||||
needPlotLine = true;
|
||||
invertOrientation = false;
|
||||
|
||||
//Obtain the minimum and maximum values of Xdata
|
||||
minMaxLoc(plotDataX,&MinX,&MaxX);
|
||||
@@ -384,7 +387,6 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Vertical Y axis
|
||||
drawLine(ImageXzero, ImageXzero, 0, plotSizeHeight, axisColor);
|
||||
LineSpace = cvRound(LineSpace * (float)plotSizeWidth / plotSizeHeight );
|
||||
@@ -413,7 +415,6 @@ namespace cv
|
||||
|
||||
if(Ydata.at<double>(i,0)<0)
|
||||
Ydata.at<double>(i,0)=0;
|
||||
|
||||
}
|
||||
|
||||
return Ydata;
|
||||
@@ -457,18 +458,16 @@ namespace cv
|
||||
|
||||
line(plotResult, Axis_start, Axis_end, lineColor, plotLineWidth, 8, 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotData, bool _invertOrientation)
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotData)
|
||||
{
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData, _invertOrientation));
|
||||
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData));
|
||||
}
|
||||
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY, bool _invertOrientation)
|
||||
Ptr<Plot2d> Plot2d::create(InputArray _plotDataX, InputArray _plotDataY)
|
||||
{
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY, _invertOrientation));
|
||||
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user