Plot函數(OpenCV)

來源:互聯網
上載者:User
CPlot簡介

Matlab的plot函數非常的強大,進行資料顯示的效果非常的好,但是經常使用Opencv的同學如果每次將計算之後的資料匯入到Matlab裡顯示又比較麻煩,因此決定寫一類似於plot的C函數,用於在OpenCV中進行資料顯示。設計一個Plot類,項目位於github上https://github.com/libing64/CPlot

 主要參數
private://視窗大小int window_height;int window_width;vector< vector<CvPoint2D64f> >dataset;//一個Figure中顯示的資料集public:IplImage* Figure;// 用於顯示的圖片// manual or automatic 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;//邊界大小int border_size;
常用函數
//分別加上幾種資料類型,你可以嘗試改為C++的泛型設計void plot(int *x, int *y, size_t Cnt, CvScalar color);void plot(float *x, float *y, size_t Cnt, CvScalar color);void plot(double *x, double *y, size_t Cnt, CvScalar color);//添加標籤void xlabel(string xlabel_name, CvScalar label_color);void ylabel(string ylabel_name, CvScalar label_color);//清空資料void clear();//添加titlevoid title(string title_name);
實現

到項目首頁上Plot.cpp中有完整的代碼實現 https://github.com/libing64/CPlot

範例
#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;}
顯示效果

如何自己最佳化

如果感覺這些代碼並不夠優,你可以自己去最佳化它

  • 註冊一個github的帳號
  • 進入項目首頁 https://github.com/libing64/CPlot
  • 點擊fork
  • 進入自己的項目首頁git clone git git@github.com:yourname/CPlot.git
  • 修改代碼並commit

    git commit -m "commit"

  • 當感覺自己寫的比較優秀的時候可以,與原始項目合并,點擊pull

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.