plot_demo.cpp 1.06 KB
Newer Older
1 2 3 4 5 6 7 8
#include <opencv2/highgui.hpp>
#include <opencv2/plot.hpp>
#include <iostream>

using namespace cv;

int main()
{
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
9 10
    Mat data_x( 1, 51, CV_64F );
    Mat data_y( 1, 51, CV_64F );
11

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
12
    for ( int i = 0; i < data_x.cols; i++ )
13
    {
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
14 15 16
        double x = ( i - data_x.cols / 2 );
        data_x.at<double>( 0, i ) = x;
        data_y.at<double>( 0, i ) = x * x * x;
17 18 19 20 21 22 23
    }

    std::cout << "data_x : " << data_x << std::endl;
    std::cout << "data_y : " << data_y << std::endl;

    Mat plot_result;

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
24
    Ptr<plot::Plot2d> plot = plot::Plot2d::create( data_x, data_y );
25 26
    plot->render(plot_result);

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
27
    imshow( "The plot rendered with default visualization options", plot_result );
28

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
29 30 31 32 33 34 35
    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 );
36

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
37
    imshow( "The plot rendered with some of custom visualization options", plot_result );
38 39 40 41
    waitKey();

    return 0;
}