下載地址:http://download.csdn.net/detail/xuluhui123/6369193 1、使用這個庫可以在屏幕上,或者圖像上畫曲線圖。 2、可以在測試一個算法時,非常方便的觀察到數(shù)字數(shù)組。 (1)展示一個簡單的數(shù)組曲線圖: showFloatGraph("Rotation Angle", floatArray, numFloats );//floatArray是浮點型數(shù)組首地址,numFloats是要畫出的數(shù)組的數(shù)量
例如,畫出二值圖像的水平積分投影和垂直積分投影構(gòu)成的特征矢量: Mat hist_x=hist.jisuanHist(img,1);//水平投影 Mat hist_y=hist.jisuanHist(img,0);//垂直投影 float * img_range=new float[hist_x.cols+hist_y.cols]; int i; for( i=0;i<hist_x.cols;i++) { img_range[i]=(float)hist_x.at<double>(i); } for(int j=0;i<hist_x.cols+hist_y.cols;i++,j++) { img_range[i]=(float)hist_y.at<double>(j); } showFloatGraph("水平投影和垂直投影構(gòu)成的特征矢量", img_range,hist_x.cols+hist_y.cols,0);
如下圖:
同樣的也可以顯示一個float類型的vector或者int,甚至字節(jié)數(shù)組 showFloatGraph("Rotation Angle", &floatVector[0], floatVector.size()); showIntGraph("Rotation Angle", &intVector[0], intVector.size()); showUCharGraph("Pixel Values", pixelData, numPixels);
showIntGraph("Rotation Angle", &intVector[0], intVector.size(), 0);//設置第三個顯示時間參數(shù)為0,等待,直到用戶按鍵。
(2)在一個圖像上畫多個曲線
IplImage *graphImg = drawFloatGraph(&floatVec1[0], floatVec1.size(), NULL, -25,25, 400,180, "X Angle (blue is truth, green is POSIT)" );//-25和25是數(shù)據(jù)最小值和最大值,400是窗口寬,180為高,"x angel"為曲線標簽 drawFloatGraph(&floatVec2[0], floatVec2.size(), graphImg, -25,25, 400,180);//在同樣的圖像上畫曲線 cvSaveImage("my_graph.jpg", graphImg); cvReleaseImage(&graphImg);

(3)在一個存在的圖像上畫曲線 IplImage *bgImg = cvLoadImage("lena.jpg"); int w = bgImg->width; int h = bgImg->height; drawFloatGraph(floatArray, numFloats, bgImg, -25,25, w, h, "Yaw (in degrees)"); showImage(bgImg, 0, "Rotation Angle"); cvReleaseImage(&bgImg);

(4)將三個曲線畫在一個大的圖像上 IplImage *dstImage = cvLoadImage("lena.jpg"); int W = 400, H = 150; float RANGE = 25.0f; char *name; name = "X Angle (blue is truth, green is POSIT)"; setGraphColor(0); // Start with a blue graph // Set the position of the graph within the image CvRect region = cvRect(dstImage->width-1 - W-10, 10, W+20, H+20); cvSetImageROI(dstImage, region); drawFloatGraph(&vecX1[0], vecX1.size(), dstImage, -RANGE,+RANGE, W,H, name); drawFloatGraph(&vecX2[0], vecX2.size(), dstImage, -RANGE,+RANGE, W,H); name = "Y Angle (blue is truth, green is POSIT)"; setGraphColor(0); // Start with a blue graph // Set the position of the graph within the image region.y += H+20; cvSetImageROI(dstImage, region); drawFloatGraph(&vecY1[0], vecY1.size(), dstImage, -RANGE,+RANGE, W,H, name); drawFloatGraph(&vecY2[0], vecY2.size(), dstImage, -RANGE,+RANGE, W,H); name = "Z Angle (blue is truth, green is POSIT)"; setGraphColor(0); // Start with a blue graph // Set the position of the graph within the image region.y += H+20; cvSetImageROI(dstImage, region); drawFloatGraph(&vecZ1[0], vecZ1.size(), dstImage, -RANGE,+RANGE, W,H, name); drawFloatGraph(&vecZ2[0], vecZ2.size(), dstImage, -RANGE,+RANGE, W,H); cvResetImageROI(dstImage); showImage(dstImage); cvReleaseImage(&dstImage);
|