plot_demo.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <opencv2/highgui.hpp>
  2. #include <opencv2/plot.hpp>
  3. #include <iostream>
  4. using namespace cv;
  5. int main()
  6. {
  7. Mat data_x( 1, 51, CV_64F );
  8. Mat data_y( 1, 51, CV_64F );
  9. for ( int i = 0; i < data_x.cols; i++ )
  10. {
  11. double x = ( i - data_x.cols / 2 );
  12. data_x.at<double>( 0, i ) = x;
  13. data_y.at<double>( 0, i ) = x * x * x;
  14. }
  15. std::cout << "data_x : " << data_x << std::endl;
  16. std::cout << "data_y : " << data_y << std::endl;
  17. Mat plot_result;
  18. Ptr<plot::Plot2d> plot = plot::Plot2d::create( data_x, data_y );
  19. plot->render(plot_result);
  20. imshow( "The plot rendered with default visualization options", plot_result );
  21. plot->setShowText( false );
  22. plot->setShowGrid( false );
  23. plot->setPlotBackgroundColor( Scalar( 255, 200, 200 ) );
  24. plot->setPlotLineColor( Scalar( 255, 0, 0 ) );
  25. plot->setPlotLineWidth( 2 );
  26. plot->setInvertOrientation( true );
  27. plot->render( plot_result );
  28. imshow( "The plot rendered with some of custom visualization options", plot_result );
  29. waitKey();
  30. return 0;
  31. }