下载地址:http://download.csdn.net/detail/xuluhui123/6369193 1、使用这个库可以在屏幕上,或者图像上画曲线图。 2、可以在测试一个算法时,非常方便的观察到数字数组。 (1)展示一个简单的数组曲线图: showFloatGraph("Rotation Angle", floatArray, numFloats );//floatArray是浮点型数组首地址,numFloats是要画出的数组的数量
例如,画出二值图像的水平积分投影和垂直积分投影构成的特征矢量: 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("水平投影和垂直投影构成的特征矢量", img_range,hist_x.cols+hist_y.cols,0);
如下图:
同样的也可以显示一个float类型的vector或者int,甚至字节数组 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);//设置第三个显示时间参数为0,等待,直到用户按键。
(2)在一个图像上画多个曲线
IplImage *graphImg = drawFloatGraph(&floatVec1[0], floatVec1.size(), NULL, -25,25, 400,180, "X Angle (blue is truth, green is POSIT)" );//-25和25是数据最小值和最大值,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);
|