Last active
February 3, 2021 08:00
-
-
Save UnaNancyOwen/ae41d341c054f0b1193839ecf03bb01e to your computer and use it in GitHub Desktop.
Draw Sine using cv::plot Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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