打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用opencv画曲线图

下载地址:http://download.csdn.net/detail/xuluhui123/6369193

1、使用这个库可以在屏幕上,或者图像上画曲线图。

2、可以在测试一个算法时,非常方便的观察到数字数组。

(1)展示一个简单的数组曲线图:

[html] view plaincopy
  1. showFloatGraph("Rotation Angle", floatArray, numFloats );//floatArray是浮点型数组首地址,numFloats是要画出的数组的数量  

例如,画出二值图像的水平积分投影和垂直积分投影构成的特征矢量:
[html] view plaincopy
  1.        Mat  hist_x=hist.jisuanHist(img,1);//水平投影  

  2. Mat  hist_y=hist.jisuanHist(img,0);//垂直投影  

  3. float * img_range=new float[hist_x.cols+hist_y.cols];  

  4. int i;  

  5. for( i=0;i<hist_x.cols;i++)  

  6. {     

  7.     img_range[i]=(float)hist_x.at<double>(i);  

  8. }  

  9. for(int j=0;i<hist_x.cols+hist_y.cols;i++,j++)  

  10. {  

  11.     img_range[i]=(float)hist_y.at<double>(j);  

  12. }  

  13.     showFloatGraph("水平投影和垂直投影构成的特征矢量", img_range,hist_x.cols+hist_y.cols,0);  

如下图:


同样的也可以显示一个float类型的vector或者int,甚至字节数组

[html] view plaincopy
  1. showFloatGraph("Rotation Angle", &floatVector[0], floatVector.size());  

  2. showIntGraph("Rotation Angle", &intVector[0], intVector.size());  

  3. showUCharGraph("Pixel Values", pixelData, numPixels);  

[html] view plaincopy
  1. showIntGraph("Rotation Angle", &intVector[0], intVector.size(), 0);//设置第三个显示时间参数为0,等待,直到用户按键。  

(2)在一个图像上画多个曲线

[html] view plaincopy
  1. IplImage *graphImg = drawFloatGraph(&floatVec1[0], floatVec1.size(), NULL,  

  2.     -25,25, 400,180, "X Angle (blue is truth, green is POSIT)" );//-25和25是数据最小值和最大值,400是窗口宽,180为高,"x angel"为曲线标签  

  3. drawFloatGraph(&floatVec2[0], floatVec2.size(), graphImg, -25,25, 400,180);//在同样的图像上画曲线  

  4. cvSaveImage("my_graph.jpg", graphImg);  

  5. cvReleaseImage(&graphImg);  



(3)在一个存在的图像上画曲线

[cpp] view plaincopy
  1. IplImage *bgImg = cvLoadImage("lena.jpg");  

  2. int w = bgImg->width;  

  3. int h = bgImg->height;  

  4. drawFloatGraph(floatArray, numFloats, bgImg, -25,25, w, h, "Yaw (in degrees)");  

  5. showImage(bgImg, 0, "Rotation Angle");  

  6. cvReleaseImage(&bgImg);  

(4)将三个曲线画在一个大的图像上

[cpp] view plaincopy
  1. IplImage *dstImage = cvLoadImage("lena.jpg");  

  2. int W = 400, H = 150;  

  3. float RANGE = 25.0f;  

  4. char *name;  

  5. name = "X Angle (blue is truth, green is POSIT)";  

  6. setGraphColor(0);   // Start with a blue graph  

  7. // Set the position of the graph within the image  

  8. CvRect region = cvRect(dstImage->width-1 - W-10, 10, W+20, H+20);  

  9. cvSetImageROI(dstImage, region);  

  10. drawFloatGraph(&vecX1[0], vecX1.size(), dstImage, -RANGE,+RANGE, W,H, name);  

  11. drawFloatGraph(&vecX2[0], vecX2.size(), dstImage, -RANGE,+RANGE, W,H);  

  12. name = "Y Angle (blue is truth, green is POSIT)";  

  13. setGraphColor(0);   // Start with a blue graph  

  14. // Set the position of the graph within the image  

  15. region.y += H+20;  

  16. cvSetImageROI(dstImage, region);  

  17. drawFloatGraph(&vecY1[0], vecY1.size(), dstImage, -RANGE,+RANGE, W,H, name);  

  18. drawFloatGraph(&vecY2[0], vecY2.size(), dstImage, -RANGE,+RANGE, W,H);  

  19. name = "Z Angle (blue is truth, green is POSIT)";  

  20. setGraphColor(0);   // Start with a blue graph  

  21. // Set the position of the graph within the image  

  22. region.y += H+20;  

  23. cvSetImageROI(dstImage, region);  

  24. drawFloatGraph(&vecZ1[0], vecZ1.size(), dstImage, -RANGE,+RANGE, W,H, name);  

  25. drawFloatGraph(&vecZ2[0], vecZ2.size(), dstImage, -RANGE,+RANGE, W,H);  

  26. cvResetImageROI(dstImage);  

  27. showImage(dstImage);  

  28. cvReleaseImage(&dstImage);  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
八卦、十六卦、三十二卦、六十四卦单螺旋曲线图
养孩子又不是吹气球!|教你看懂娃的生长曲线图
高中经济生活常见曲线图
矩阵类的模板实现(C++)
Excel做曲线图
HIST 第三帝國的興和亡 (下)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服