久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2480|回復: 0
打印 上一主題 下一主題
收起左側

ROS中激光雷達數據處理之特征提取 源程序

[復制鏈接]
跳轉到指定樓層
樓主
   ROS中激光雷達的數據就是一串距離值,每隔1度一個距離值(具體情況得看激光雷達的參數),通過實測激光雷達的數據提取關鍵特征,直線,圓弧

  1. // 進行多邊形擬合: Points : 輪廓上的點      n -- 輪廓點數目  Eps -- 擬合精度
  2. // 返回值: 若該輪廓段需要分段,則返回分段點在該輪廓點列中的索引,否則,返回 0 表示不需要分段
  3. // 這里是整個算法計算復雜性最大的一個地方
  4. // 為了提高程序運行效率,對點到直線的距離計算進行改進:
  5. // 多邊形擬合中的直線是由點列中的點決定的
  6. // 為了計算點到直線的距離,
  7. // 采用坐標系旋轉,將直線旋轉到x軸方向,這樣點到直線的距離即為各個點
  8. // 在坐標旋轉后的y值的絕對值
  9. // 同時,坐標旋轉矩陣在該次運算中為定值,只需一次計算,不需要多次的開方或三角計算
  10. int OpenRadar::PolyContourFit( int* X, int* Y, int n , float Eps ) // 根據輪廓點,用多邊形擬合該輪廓點   
  11. {
  12.     double dis = sqrt((double)(((X[0] - X[n - 1])*(X[0] - X[n - 1])) +  
  13.                      ((Y[0] - Y[n - 1])* (Y[0] - Y[n - 1]))));
  14.     double cosTheta = (X[n- 1] - X[0]) / dis;
  15.     double sinTheta = - ( Y[n- 1] - Y[0] )/dis;
  16.     double MaxDis = 0;
  17.     int i ;
  18.     int MaxDisInd = -1;
  19.     double dbDis;
  20.     for(i = 1 ; i < n - 1 ; i++)
  21.     {
  22.         // 進行坐標旋轉,求旋轉后的點到x軸的距離
  23.         dbDis = abs( (Y[i] - Y[0]) * cosTheta + (X[i] - X[0])* sinTheta);
  24.         if( dbDis > MaxDis)
  25.         {
  26.             MaxDis = dbDis;
  27.             MaxDisInd = i;
  28.         }
  29.     }
  30.     if(MaxDis > Eps)
  31.     {
  32.         return MaxDisInd;
  33.         //        cout << "Line 1 : " << endl;
  34.         //        cout << "Start :" << Points[0].x << "  " << Points[0].y  << " --- " << Points[MaxDisInd].x << "  " << Points[MaxDisInd].y << endl;
  35.         //        cout << "角度: "<<180 * atan2(Points[0].y - Points[MaxDisInd].y , Points[0].x - Points[MaxDisInd].x ) / 3.1415926;
  36.         //        cout << "Line 2 :" << endl;
  37.         //        cout << "Start :" << Points[MaxDisInd].x << "  " << Points[MaxDisInd].y  << " --- " << Points[n - 1].x << "  " << Points[n - 1].y << endl;
  38.         //        cout << "角度: "<< 180 * atan2(Points[n - 1].y - Points[MaxDisInd].y , Points[n - 1].x - Points[MaxDisInd].x ) / 3.1415926;
  39.     }
  40.     //    else{
  41.     //        cout << "Line 1 : " << endl;
  42.     //        cout << "Start :" << Points[0].x << "  " << Points[0].y  << " --- " << Points[n - 1].x << "  " << Points[n - 1].y << endl;
  43.     //        cout << "角度: "<<180 * atan2(Points[n - 1].y - Points[0].y , Points[n - 1].x - Points[0].x ) / 3.1415926;

  44.     //    }
  45.     return 0;
  46. }

  47. //將折線拆成兩段
  48. int OpenRadar::BreakPolyLine(vector<int>& BreakedRadarRho,
  49.                              vector<double>& BreakedRadarTheta,
  50.                              vector<int>& SepRadarRho ,   
  51.                              vector<double>&SepRadarTheta)
  52. {
  53.     int rho = 0;
  54.     double theta = 0.0;
  55.     int X[1200] = {0};
  56.     int Y[1200] = {0};
  57.     int rhoCopy[1200] = {0};
  58.     double thetaCopy[1200] = {0};
  59.     int pointCnt = 0;
  60.     int lineCnt = 0;
  61.     int N = 0;
  62.     SepRadarRho.clear();
  63.     SepRadarTheta.clear();
  64.     Corners.clear();

  65.     //進行多次迭代,將所有的折線都拆分成直線段
  66.    
  67.    vector<int>CornerIndex;
  68.    int CornerCnt = 0;
  69.    int tempIndex = 0;
  70.     for (int i = 0; i < static_cast<int>(BreakedRadarRho.size());i++)
  71.     {
  72.         rho   = BreakedRadarRho.at(i);
  73.         theta = BreakedRadarTheta.at(i);

  74.         if (rho < 0)
  75.         {
  76.             if (pointCnt > 200)//數目比較少的點直接拋棄
  77.             {
  78.                 CornerIndex.clear();
  79.                 CornerCnt = FindCorners(CornerIndex,X,Y,0,pointCnt,200);

  80.                 if (CornerIndex.size() == 0)
  81.                 {
  82.                     for (int k = 0 ; k < pointCnt;k++)
  83.                     {
  84.                         SepRadarRho.push_back(rhoCopy[k]);
  85.                         SepRadarTheta.push_back(thetaCopy[k]);
  86.                     }
  87.                     SepRadarRho.push_back(-1);
  88.                     SepRadarTheta.push_back(1000.0);
  89.                     lineCnt++;
  90.                 }else
  91.                 {
  92.                     tempIndex = 0;
  93.                     for (int k = 0 ; k < pointCnt;k++)
  94.                     {
  95.                         SepRadarRho.push_back(rhoCopy[k]);
  96.                         SepRadarTheta.push_back(thetaCopy[k]);
  97.                         if (k == CornerIndex.at(tempIndex))
  98.                         {
  99.                             SepRadarRho.push_back(-1);
  100.                             SepRadarTheta.push_back(1000.0);
  101.                             lineCnt++;
  102.                             if (tempIndex < static_cast<int>(CornerIndex.size()) -1)
  103.                             {
  104.                                 tempIndex++;
  105.                             }  
  106.                         }
  107.                     }
  108.                     SepRadarRho.push_back(-1);
  109.                     SepRadarTheta.push_back(1000.0);
  110.                     lineCnt++;
  111.                 }
  112.             }
  113.             pointCnt = 0;
  114.             continue;
  115.         }
  116.         X[pointCnt] = static_cast<int>(rho*cos(theta));
  117.         Y[pointCnt] = static_cast<int>(rho*sin(theta));
  118.         rhoCopy[pointCnt]   = rho;
  119.         thetaCopy[pointCnt] = theta;
  120.         pointCnt++;
  121.     }
  122.    
  123.     //cout<<"lineCnt: "<<lineCnt<<endl;
  124.     return lineCnt;
  125. }

  126. //進行直線擬合
  127. void OpenRadar::FitLine(vector<LinePara>& FittedLine,vector<int>& RadarRho,vector<double>& RadarTheta){

  128.     int rho = 0;
  129.     double theta = 0.0;
  130.     int X[1200] = {0};
  131.     int Y[1200] = {0};
  132.     int pointCnt = 0;
  133.     LinePara tmpLinePara;
  134.     FittedLine.clear();
  135.     for (int i = 0 ; i < static_cast<int>(RadarRho.size());i++)
  136.     {
  137.         rho = RadarRho.at(i);
  138.         theta = RadarTheta.at(i);

  139.         if (rho < 0)
  140.         {
  141.             if (pointCnt > 100 )//點數目足夠多的點列才進行直線擬合
  142.             {
  143.                 WeightedFit(X ,Y ,pointCnt,&tmpLinePara);
  144.                 FittedLine.push_back(tmpLinePara);

  145.                 //存儲擬合的數據和擬合結果
  146.        /*         FILE* pF = fopen("line.txt","w");
  147.                 fprintf(pF,"[a]\n");
  148.                 fprintf(pF,"%f\n",tmpLinePara.a);
  149.                 fprintf(pF,"[b]\n");
  150.                 fprintf(pF,"%f\n",tmpLinePara.b);
  151.                 fprintf(pF,"[x]\n");
  152.                 for (int j = 0; j < pointCnt ;j++)
  153.                 {
  154.                     fprintf(pF,"%d,",X[j]);
  155.                 }
  156.                 fprintf(pF,"\n[y]\n");
  157.                 for (int j = 0; j < pointCnt ;j++)
  158.                 {
  159.                     fprintf(pF,"%d,",Y[j]);
  160.                 }
  161.                 fclose(pF);*/

  162.                 pointCnt = 0;
  163.                 continue;
  164.             }else {
  165.                 pointCnt = 0;
  166.                 continue;
  167.             }   
  168.         }

  169.         X[pointCnt] = static_cast<int>(rho*cos(theta));
  170.         Y[pointCnt] = static_cast<int>(rho*sin(theta));
  171.         pointCnt++;
  172.     }
  173.    /* for (int i = 0; i < FittedLine.size();i++)
  174.     {
  175.         cout<<"a: "<<FittedLine.at(i).a<<"  b: "<<FittedLine.at(i).b<<" ";
  176.         cout<<"x1: "<<FittedLine.at(i).startPoint.x<<" "
  177.             <<"y1: "<<FittedLine.at(i).startPoint.y<<" "
  178.             <<"x1: "<<FittedLine.at(i).endPoint.x<<" "
  179.             <<"y1: "<<FittedLine.at(i).endPoint.y<<endl;
  180.     }*/

  181. }
復制代碼


以上代碼: OpenRadar7.0.zip (25.96 KB, 下載次數: 13)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 香蕉婷婷| 成人免费视频网站在线看 | 日本午夜在线视频 | 国产精品资源在线观看 | 欧洲亚洲视频 | 日韩免费一区二区 | 人人澡人人射 | 国产精品99久久久久久久久久久久 | 一区二区三区欧美大片 | 亚洲综合色自拍一区 | 久久亚洲天堂 | 色婷婷久久 | 给我免费的视频在线观看 | 免费在线观看一级毛片 | 蜜桃精品噜噜噜成人av | 亚洲精品www| 日日干日日色 | 日韩高清一区 | 精品九九九 | 欧美一区二区三区四区五区无卡码 | 国产一区二区三区免费 | 精品在线观看一区二区 | 欧美一区二区三区在线观看 | 国产成人麻豆免费观看 | 偷拍自拍在线观看 | 国产精品不卡一区 | 国产精品毛片一区二区在线看 | 久久中文字幕一区 | 亚洲在线一区二区 | 精品在线一区 | 青青草视频网站 | 福利社午夜影院 | 亚洲精选一区二区 | 精品日韩 | 日本欧美国产在线 | 国产精品久久久久久久久久久免费看 | 伊人伊人 | www.精品一区| 天天干狠狠操 | 成人午夜网站 | 粉嫩粉嫩芽的虎白女18在线视频 |