Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen
Last active February 3, 2021 08:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save UnaNancyOwen/ae41d341c054f0b1193839ecf03bb01e to your computer and use it in GitHub Desktop.
Save UnaNancyOwen/ae41d341c054f0b1193839ecf03bb01e to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment