ceres學習之平面擬合

背景:orb-slam2最終保存的軌跡形成的平面是一個傾斜的,這個與相機初始化位置有關,但是有些時候,我們需要的是一個2d的軌跡的試圖,直接將軌跡向某一個平面投影的話。

得到的估計是失真的,所以我們需要對軌跡的location數據進行處理,就是首先擬合出軌跡的平面,然后將這個平面繞著一個軸,旋轉一定的角度,將其旋轉成與某一個做表面平行,

然后再取出其中兩個維度的坐標,那么我們就可以得到一個真是的2d平面。為實現上面的目的,第一步工作就是要根據輸入的坐標數據,3d坐標點,擬合出一個主平面,使用ceres

優化求解平面的四個參數a,b,c,d的值。這個過程主要是熟悉使用ceres優化特定問題的一個框架,然后根據實際的問題,去填入具體的殘差函數,等。

planeFitting.h

#include <iostream>
#include <ceres/ceres.h>
#include <ceres/rotation.h>struct OptimalPlanFitting
{OptimalPlanFitting(double x, double y, double z):x_(x), y_(y), z_(z){}template<typename T>bool operator()(const T* const a, const T* const b, const T* const c, const T* const d,T* residual)const{T temp = a[0]*x_ + b[0]*y_ + c[0]*z_ + d[0];residual[0] = temp*temp/(a[0]*a[0] + b[0]*b[0] + c[0]*c[0]);return true;}static ceres::CostFunction* cost(double x, double y, double z){return(new ceres::AutoDiffCostFunction<OptimalPlanFitting, 1, 1, 1, 1, 1>(new OptimalPlanFitting(x, y, z)));}
private:const double x_;const double y_;const double z_;};

planeFitting.cpp

#include <iostream>
#include <ceres/ceres.h>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Geometry>
#include <string>
#include <fstream>
#include "planeFitting.h"
using namespace std;
using namespace ceres;int split(std::string str, std::string pattern, std::vector<std::string> &words)
{std::string::size_type pos;std::string word;int num = 0;str += pattern;std::string::size_type size = str.size();for (auto i = 0; i < size; i++){pos = str.find(pattern, i);if (pos == i){continue;//if first string is pattern}if (pos < size){word = str.substr(i, pos - i);words.push_back(word);i = pos + pattern.size() - 1;num++;}}return num;
}
void readFile(std::string filePath, std::vector<Eigen::Vector3d>& locations)
{ifstream infile;infile.open(filePath);if(!infile){std::cout<<"filed to load trajectory data"<<std::endl;return;}string str;std::vector<string> words;while(!infile.eof()){words.clear();std::getline(infile, str);split(str, " ", words);Eigen::Vector3d position(atof(const_cast<const char *>(words[1].c_str())),atof(const_cast<const char *>(words[2].c_str())),atof(const_cast<const char *>(words[3].c_str())));locations.push_back(position);    }
}
//這邊傳參數,要使用double 類型
//double *params或者是這樣
int planFittingOptimal(std::vector<Eigen::Vector3d> locations, double params[4])
{//double params[4]={1.0,0.1,0.1,0.2};ceres::Problem problem;for(int i = 0; i<locations.size(); i++){Eigen::Vector3d loc = locations[i];//std::cout<<loc<<std::endl;ceres::CostFunction *cost_func = OptimalPlanFitting::cost(loc.x(), loc.y(), loc.z());problem.AddResidualBlock(cost_func, new ceres::HuberLoss(1.0), &params[0], &params[1], &params[2], &params[3]);}ceres::Solver::Options options;options.linear_solver_type = ceres::SPARSE_SCHUR;options.trust_region_strategy_type = ceres::LEVENBERG_MARQUARDT;options.max_num_iterations = 50;options.minimizer_progress_to_stdout = true;ceres::Solver::Summary summary;ceres::Solve(options, &problem, &summary);std::cout<<summary.BriefReport()<<"\n";std::cout<<"a: "<<params[0]<<" \nb:"<<params[1]<<" \nc:"<<params[2]<<"\nd:"<<params[3]<<std::endl;}
int main()
{double params[4]={1.0,0.1,0.2,0.1};std::string filePath = "/home/yunlei/COOL/ceres-study/data/CameraTrajectory_common.txt";std::vector<Eigen::Vector3d> locations;readFile(filePath, locations);//std::cout<<"locations.size(): "<<locations.size()<<std::endl;planFittingOptimal(locations, params);std::cout<<params[0]<<" "<<params[1]<<" "<<params[2]<<" "<<params[3]<<std::endl;return 0;
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/252339.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/252339.shtml
英文地址,請注明出處:http://en.pswp.cn/news/252339.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

二維樹狀數組模板(區間修改+區間查詢)

二維樹狀數組模板(區間修改區間查詢) 例題&#xff1a;JOIOI上帝造題的七分鐘 一共兩種操作&#xff1a; \(L\ x_1\ y_1\ x_2\ y_2\ d\)&#xff1a;把\((x_1,y_1)\)&#xff0c;\((x_2,y_2)\)這個矩形內所有元素加\(d\)。\(k\ x_1\ y_1\ x_2\ y_2\)&#xff1a;查詢\((x_1,y_1…

egg(110,111,112)--egg之微信支付

微信支付前的準備工作 準備工作 準備工作&#xff1a;個體工商戶、企業、政府及事業單位。需要獲取內容 appid&#xff1a;應用 APPID&#xff08;必須配置&#xff0c;開戶郵件中可查看&#xff09;MCHID&#xff1a;微信支付商戶號&#xff08;必須配置&#xff0c;開戶郵件中…

解決圖片跨域問題

var imgs new Image(); imgs.crossOrigin "Anonymous"; //注意存放順序 imgs.src "http://192.168.0.107/ZHCX/CGZSIMG/1.jpg"; imgs.onload function () { var canvas document.createElement(canvas); canvas.width imgs.width; canvas.height i…

旋轉三維平面與某一坐標平面平行

在上一篇文章&#xff08;https://blog.csdn.net/weixin_38636815/article/details/109495227&#xff09;中我寫了如何使用ceres&#xff0c;根據一系列的點來擬合一個平面&#xff0c;很難保證ORB-SLAM輸出的軌跡嚴格與某一個坐標平面平行&#xff0c;所以這篇文章我我將說一…

elasticsearch的插件安裝

目前使用的是2.4.5版本的es 安裝的時候注意以下幾點 : 1.如果想所有的ip都能訪問es,需要修改config下的elasticsearch.yml.修改如下 network.host0.0.0.02.安裝查詢插件 : 進入es的安裝目錄,執行以下命令 ./bin/plugin install mobz/elasticsearch-head3.安裝刪除插件 目前不支…

let const緩存for循環的中間變量

es5中使用在for-in for循環中注冊異步事件&#xff0c;異步事件中的i總是最后一個值。使用es6的let const可以解決 let obj {a: 1,b: 1,c: 1 }// es5 for循環中 var聲明 i let funcs [] for (var key in obj) {funcs.push(() > {console.log(key)}) } funcs.forEach(func …

BZOJ1439 : YY的問題

考慮容斥&#xff0c;枚舉哪些不存在的邊選中了&#xff0c;剩下的不管&#xff0c;則可以用組合數計算方案數。 時間復雜度$O(m2^mnm)$。 #include<cstdio> const int N550,B10000,MAXL350; int n,m,S,i,j,e[N][2],g[N],f[N]; inline int max(int a,int b){return a>…

windows下配置opencv

我的windows下是使用的一個鏡像安裝的vs2015&#xff0c;然后在vs上編譯工程需要使用opencv時&#xff0c;需要在工程中配置opencv 新建一個C工程&#xff0c;按照下面的步驟進行配置。 設置opencv的環境變量 “此電腦”右鍵點擊“屬性”-->選擇“高級系統設置”-->選…

關于spring MVC中加載多個validator的方法。

首先講下什么叫做validator&#xff1a; validator是驗證器&#xff0c;可以驗證后臺接受的數據&#xff0c;對數據做校驗。 SpringMVC服務器驗證有兩種方式,一種是基于Validator接口,一種是使用Annotaion JSR-303標準的驗證。 1.使用Annotaion JSR-303標準的驗證 使用這個需要…

面試時,面試官到底在考察什么?

作者&#xff1a;白海飛出處&#xff1a;極客時間《面試現場》專欄 先看一段面試對話&#xff0c;“大面”是一位久經沙場的面試官&#xff0c;小明就是今天的應聘者。一通面試下來&#xff0c;前面的技術問題小明都對答如流&#xff0c;雙方相談甚歡&#xff0c;接下來面試官“…

NoSQL-MongoDB with python

前言&#xff1a; MongoDB&#xff0c;文檔存儲型數據庫&#xff08;document store&#xff09;。NoSQL數據庫中&#xff0c;它獨占鰲頭&#xff0c;碾壓其他的NoSQL數據庫。 使用C開發的&#xff0c;性能僅次C。與redis一樣&#xff0c;開源、高擴展、高可用。 基于分布式文件…

RHCS

云計算與大數據 黑洞 RHCS(概念篇) 一、 什么是RHCS RHCS是Red Hat Cluster Suite的縮寫&#xff0c;也就是紅帽子集群套件&#xff0c;RHCS是一個能夠提供高可用性、高可靠性、負載均衡、存儲共享且經濟廉價的集群工具集合&#xff0c;它將集群系統中三大集群架構融合一體&…

深度圖壓縮之-高低8位拆分保存

使用kinect相機保存數據&#xff0c;為了減少保存的數據集量&#xff0c;對圖像進行壓縮。將彩色圖像直接壓縮成.mp4格式&#xff0c;此時圖像上的一些高頻信息會被損失掉。 為了能夠讓深度圖有比較高的保真度&#xff0c;減少深度圖上高頻信息的損失&#xff0c;我們將16位的…

linux 一個超簡單的makefile

2019獨角獸企業重金招聘Python工程師標準>>> makefile 自動化變量&#xff1a; $ : 規則的目標文件名 例如&#xff1a;main:main.o test.o g -Wall -g main.o test.o -o main 可以寫成&#xff1a; main:main.o test.o g -Wall -g main.o test.o -o $ $< : …

poj2480(利用歐拉函數的積性求解)

題目鏈接: http://poj.org/problem?id2480 題意&#xff1a;∑gcd(i, N) 1<i <N&#xff0c;就這個公式&#xff0c;給你一個n&#xff0c;讓你求sumgcd(1,n)gcd(2,n)gcd(3,n)…………gcd(n-1,n)gcd(n,n),&#xff08;1<n<2^31&#xff09;是多少&#xff1f; 放…

跨域問題

一、為什么會有跨域問題&#xff1f; 是因為瀏覽器的同源策略是對ajax請求進行阻攔了&#xff0c;但是不是所有的請求都給做跨域&#xff0c;像是一般的href屬性&#xff0c;a標簽什么的都不攔截。 二、解決跨域問題的兩種方式 JSONPCORS 三、JSONP 先簡單來說一下JSONP&#x…

PAT A1052

這個需要注意的是相關的string轉整數或者double的函數&#xff1b;詳見這個鏈接blog #include <iostream> #include <string> using namespace std; bool isPrime(int n) {if (n 0 || n 1) return false;for (int i 2; i * i < n; i)if (n % i 0) return fa…

php審計學習:xdcms2.0.8注入

注入點Fields: 注冊頁面會引用如下方法: $fields 變量是從 $fields$_POST[fields]; 這里獲取&#xff0c; 在代碼里沒有過濾。 打印 fields 數據查看: 從代碼上看 $field_sql.",{$k}{$f_value}"; 最終會變成: ,truename111111,email12345 因為 $field_sql 最終會引入…

windows下安裝python和Python-opencv

背景&#xff1a;目前基于python的圖像處理和機器視覺的研究還挺多&#xff0c;最近不是在研究目標檢測和目標跟蹤的算法&#xff0c;由于檢測和跟蹤的環境比較簡單所以從不帶學習的跟蹤方法&#xff0c;在搜索資料時搜到這個網站&#xff0c;是對opencv中的目標跟蹤算法的一個…

捋一捋js面向對象的繼承問題

說到面向對象這個破玩意&#xff0c;曾經一度我都處于很懵逼的狀態&#xff0c;那么面向對象究竟是什么呢&#xff1f;其實說白了&#xff0c;所謂面向對象&#xff0c;就是基于類這個概念&#xff0c;來實現封裝、繼承和多態的一種編程思想罷了。今天我們就來說一下這其中繼承…