namespace :

cv::vec2d;

  1. void src2ipm(cv::Mat &srcimage, cv::Mat& uvgrid, cv::Mat& outimage, cv::Mat& coord, cv::Size& sz, double ht, double roll, double pitch, double* camera_param_KK)
  2. {
  3.  
  4. int height = (int)(ht*1000); //unit-mm.
  5. double fx = camera_param_KK[0];
  6. double fy = camera_param_KK[4];
  7. double cx = camera_param_KK[2];
  8. double cy = camera_param_KK[5];
  9.  
  10. double c1 = cos(pitch*PI / 180);
  11. double s1 = sin(pitch*PI / 180);
  12. double c2 = cos(roll*PI / 180);
  13. double s2 = sin(roll*PI / 180);
  14.  
  15. double means = cv::mean(srcimage).val[0];
  16.  
  17. outimage = cv::Mat::zeros(sz.height, sz.width, CV_64FC1);
  18. coord = cv::Mat::zeros(sz.height, sz.width, CV_64FC2);//
  19.  
  20. for (int i = 0; i < sz.height; i++)
  21. {
  22. for (int j = 0; j < sz.width; j++)
  23. {
  24. float ui = uvgrid.at<double>(0, i*sz.width + j);
  25. float vi = uvgrid.at<double>(1, i*sz.width + j);
  26. //cout << "vi: " << vi << endl;
  27. if (ui<0 || ui>1278)
  28. outimage.at<double>(i, j) = means / 255;
  29. else
  30. {
  31. int x1 = (int)ui, x2 = (int)(ui + 1);
  32. int y1 = (int)vi, y2 = (int)(vi + 1);
  33. float x = ui - (float)x1;
  34. float y = vi - (float)y1;
  35.  
  36. double val = srcimage.at<uchar>(y1, x1)*(1 - x)*(1 - y) +
  37. srcimage.at<uchar>(y1, x2)*x*(1 - y) +
  38. srcimage.at<uchar>(y2, x1)*(1 - x)*y +
  39. srcimage.at<uchar>(y1, x1)* x* y;
  40. outimage.at<double>(i, j) = val/255;
  41. //
  42. coord.at<cv::Vec2d>(i, j)[1] =
  43. height*(fy*s1 + cy*c1 - y1*c1) / (fy*c1 - cy*s1 + y1*s1)*(1 - y) +
  44. height*(fy*s1 + cy*c1 - y2*c1) / (fy*c1 - cy*s1 + y2*s1)*y;
  45. double y_w = coord.at<cv::Vec2d>(i, j)[1];
  46. coord.at<cv::Vec2d>(i, j)[0] = (s1*y_w + height*c1)*(cx - x1) / fx; //Vec2d
  47. }
  48. }
  49. }
  50. outimage = outimage*255;
  51. //cout << "coordinate.rows: " << coordinate_.rows << "--- coordinate.cols: " << coordinate_.cols << endl;
  52.  
  53. //imshow("ipm", outimage);
  54. //cv::waitKey(0);
  55. //imwrite("./ipm.png", outimage);
  56. }

  

cv::Mat temp = cv::Mat::ones(3, uv.cols, CV_64FC1);

  1. void xyp2ipmp(cv::Mat& xyp, cv::Mat& ipmp, cv::Mat& xylim, Size sz){
  2.  
  3. //xylimist_[0]-latteral/xylimist_[1]-longitudinal...
  4. //ipmp-row0-cols-latteral/ipmp-row1-rows-longitudinal...
  5.  
  6. std::cout << "start probp2ipmp: " << std::endl;
  7. double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  8. minMaxLoc(xylim.row(0), &xmin, &xmax);
  9. minMaxLoc(xylim.row(1), &ymin, &ymax);
  10.  
  11. double stepcol = (xmax - xmin) / sz.width;
  12. double steprow = (ymax - ymin) / sz.height;
  13.  
  14. cv::Mat tempx = cv::Mat::ones(1, xyp.cols, CV_64FC1) * xmin;
  15. cv::Mat tempy = cv::Mat::ones(1, xyp.cols, CV_64FC1) * ymax;
  16.  
  17. ipmp = cv::Mat::zeros(2, xyp.cols, CV_8UC1);
  18. ipmp.rowRange(0, 1) = ( xyp.rowRange(0, 1) - tempx ) / stepcol;
  19. ipmp.rowRange(1, 2) = ( tempy - xyp.rowRange(1, 2) ) / steprow;
  20.  
  21. }

  

save image:

char output_path[100];

sprintf(output_path,"./ipmp/00000%05d.png",cnt);
cv::imwrite(output_path, ipm3);

vec2d的更多相关文章

  1. [LeetCode] Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  2. Package gp in the OpenCASCADE

    Package gp in the OpenCASCADE eryar@163.com China 一.简介 Introduction to Package gp gp是几何处理程序包(Geometr ...

  3. C++ STL,list vector区别

    顺序性容器: 向量 vector :   是一个线性顺序结构.相当于数组,但其大小可以不预先指定,并且自动扩展.它可以像数组一样被操作,由于它的特性我们完全可以将vector 看作动态数组.在创建一个 ...

  4. Flatten 2D Vector

    Implement an iterator to flatten a 2d vector. For example, Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  5. LeetCode Flatten 2D Vector

    原题链接在这里:https://leetcode.com/problems/flatten-2d-vector/ 题目: Implement an iterator to flatten a 2d v ...

  6. opencv基本的数据结构(转)

    DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...

  7. c++容器(vector、list、deque)

    vector ,deque 和 list 顺序性容器: 向量 vector :   是一个线性顺序结构.相当于数组,但其大小可以不预先指定,并且自动扩展.它可以像数组一样被操作,由于它的特性我们完全可 ...

  8. 边工作边刷题:70天一遍leetcode: day 84

    Flatten 2D Vector 要点: 这题是2d的iterator,一般对于1d的情况,hasNext()是不需要做移动的.而2d不同,core iterator是j向的,而i向要在hasNex ...

  9. opencv3中的机器学习算法之:EM算法

    不同于其它的机器学习模型,EM算法是一种非监督的学习算法,它的输入数据事先不需要进行标注.相反,该算法从给定的样本集中,能计算出高斯混和参数的最大似然估计.也能得到每个样本对应的标注值,类似于kmea ...

随机推荐

  1. WPF编程学习 —— 样式

     本文目录 1.引言 2.怎样使用样式? 3.内联样式 4.已命名样式 5.元素类型样式 6.编程控制样式 7.触发器 1.引言 样式(Style),主要是用来让元素或内容呈现一定外观的属性.WPF中 ...

  2. 20170814xlVBA部分代号收盘价转置

    原始数据: 转置效果: Sub TransformData() Dim Rng As Range Dim Arr As Variant Dim Dic As Object Dim dCode As O ...

  3. 4-2 Ajax练习题,12结算!Check Out。

    练习题:在购物车的每个商品旁添加按钮,按一下减一个,数量为0删除该商品.先用普通方法再用Ajax支持. 1.自定义方法decrease, 为其设定路径routes.rb. 在resouurces :l ...

  4. codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)

    题意:求使pi(n)*q<=rub(n)*p成立的最大的n. 先收集所有的质数和回文数.质数好搜集.回文数奇回文就0-9的数字,然后在头尾添加一个数.在x前后加a,就是x*10+a+a*pow( ...

  5. js下载图片

    DownloadImgZP = imgPath => { const image = new Image(); // 解决跨域 Canvas 污染问题 image.setAttribute('c ...

  6. thinkphp数组处理

    1.array_unique() 移除数组中的重复的值,并返回结果数组.当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除,对每个值只保留第一个遇到的键名,接着忽略所有后面的键名.返回的数组 ...

  7. 4. Median of Two Sorted Arrays *HARD* -- 查找两个排序数组的中位数(寻找两个排序数组中第k大的数)

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  8. struts2 正确配置通配符方式访问,报错解决

    今天遇到正确配置通配符访问action的方法,但是还是报错,原因struts 2.3 以后会内部会验证是否允许该方法,而我用的刚好是2.5的版本 要action配置中加上<allowed-met ...

  9. Solr增删改查索引

    一.添加索引,提交文档 1.如图,我的xml文档有predicate.object字段,这些在Solr配置文档里没有,所以xml文档提交不了 2.在F:\solr-4.10.0\example\sol ...

  10. 玩转X-CTR100 l STM32F4 l ESP8266串口WIFI模块

    我造轮子,你造车,创客一起造起来!更多塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]- ESP8266是一款非常火的WIFI模块,性价 ...