Cplot Introduction
The plot function of MATLAB is very powerful, and the data display effect is very good. However, it is troublesome for people who often use opencv to import the calculated data into MATLAB for display, therefore, I decided to write a C function similar to plot for data display in opencv. Design a plot class where the project is located on GitHub https://github.com/libing64/CPlot
Main Parameters
PRIVATE: // window size int window_height; int window_width; vector <cvpoint2d64f> dataset; // public: iplimage * figure; // The image to be displayed // manual or automatic range // display ratio and range bool custom_range_y; double y_max; double y_min; double y_scale; bool custom_range_x; double x_max; double x_min; double x_scale; // boundary size int border_size;
Common functions
// Add several data types respectively. You can try to change it to the generic design void plot (int * X, int * y, size_t CNT, cvscalar color) of C ++ ); void plot (float * X, float * y, size_t CNT, cvscalar color); void plot (double * X, double * y, size_t CNT, cvscalar color ); // Add the tag void xlabel (string xlabel_name, cvscalar label_color); void ylabel (string ylabel_name, cvscalar label_color); // clear the data void clear (); // Add titlevoid title (string title_name );
Implementation
Complete code implementation https://github.com/libing64/CPlot in plot. cpp on the project Homepage
Example
#include "cv.h"#include "highgui.h"#include "plot.h"#include<iostream>int main(int argc, char* argv[]){ const int Cnt = 100; double X[Cnt] = {0}; double Y[Cnt] = {0}; for(int i = 0; i < Cnt; i++) { X[i] = (double)i; Y[i] = (double)4*i - 20; } cvNamedWindow("hello",1); Plot plot; CvScalar color = CV_RGB(255, 0, 0); plot.plot(X, Y, Cnt, color); cvShowImage("hello", plot.Figure); cvWaitKey(0); //plot.clear(); for(int i = 0; i < Cnt; i++) { X[i] = (double)i; Y[i] = (double)(5*i - 20); } plot.plot(X, Y, Cnt, color); cvShowImage("hello", plot.Figure); cvWaitKey(0); for(int i = 0; i < Cnt; i++) { X[i] = (double)i; Y[i] = (double)(-5*i - 20); } plot.plot(X, Y, Cnt, color); cvShowImage("hello", plot.Figure); cvWaitKey(0); for(int i = 0; i < Cnt; i++) { X[i] = (double)i; Y[i] = (double)(50*sin(i*0.1)); } plot.plot(X, Y, Cnt, color); cvShowImage("hello", plot.Figure); cvWaitKey(0); int X2[Cnt] = {0}; int Y2[Cnt] = {0}; for(int i = 0; i < Cnt; i++) { X2[i] = i; Y2[i] = -100*i - 20; } plot.clear(); plot.plot(X2, Y2, Cnt/2, color); cvShowImage("hello", plot.Figure); cvWaitKey(0); return 0;}
Display Effect
How to optimize by yourself
If you feel that the Code is not good enough, you can optimize it yourself.
- Register a GitHub account
- Go to project homepage https://github.com/libing64/CPlot
- Click fork
- Go to your own project homepage git clone git git@github.com: yourname/cplot. Git
-
Modify code and commit
Git commit-M "commit"
- When you feel that you write well, You can merge it with the original project and click pull.