UnaNancyOwen
11/3/2016 - 3:34 PM

Draw Sine using cv::plot Module

Draw Sine using cv::plot Module

#include <vector>
#include <cmath>
#include <opencv2/opencv.hpp>
#include <opencv2/plot.hpp>

int main( int argc, char* argv[] )
{
    // Initialize Data
    std::vector<double> sine;
    for( int t = 0; t < 360; t++ ){
        sine.push_back( std::sin( t * CV_PI / 180.0 ) );
    }

    // Create Ploter
    cv::Mat data( sine );
    cv::Ptr<cv::plot::Plot2d> plot = cv::plot::createPlot2d( data );

    while( true ){
        // Rotation Data
        double value = *sine.begin();
        sine.erase( sine.begin() );
        sine.push_back( value );

        // Render Plot Image
        cv::Mat image;
        plot->render( image );

        // Show Image
        cv::imshow( "sine", image );
        if( cv::waitKey( 33 ) >= 0 ){
            break;
        }
    }
    
    cv::destroyAllWindows();

    return 0;
}