ceres---相机重投影误差

摘要:
相机重投影误差相机归一化公式:相机归一化与外参变换公式:相机畸变:代码://TemplatedpinholecameramodelforusedwithCeres.Thecamerais//parameterizedusing9parameters:3forrotation,3fortranslation,1for//focallengthand2forradialdistortion.Thepr

相机重投影误差

相机归一化公式:

ceres---相机重投影误差第1张

相机归一化与外参变换公式:

ceres---相机重投影误差第2张

相机畸变:

ceres---相机重投影误差第3张

ceres---相机重投影误差第4张

代码:

//Templated pinhole camera model for used with Ceres.  The camera is
//parameterized using 9 parameters: 3 for rotation, 3 for translation, 1 for
//focal length and 2 for radial distortion. The principal point is not modeled
//(i.e. it is assumed be located at the image center).
structSnavelyReprojectionError {
  SnavelyReprojectionError(double observed_x, doubleobserved_y)
      : observed_x(observed_x), observed_y(observed_y) {}

  template <typename T>
  bool operator()(const T* constcamera,
                  const T* constpoint,
                  T* residuals) const{
    //camera[0,1,2] are the angle-axis rotation.
    T p[3];
    AngleAxisRotatePoint(camera, point, p);

    //camera[3,4,5] are the translation.
    p[0] += camera[3];
    p[1] += camera[4];
    p[2] += camera[5];

    //Compute the center of distortion. The sign change comes from
    //the camera model that Noah Snavely's Bundler assumes, whereby
    //the camera coordinate system has a negative z axis.
    const T xp = - p[0] / p[2];
    const T yp = - p[1] / p[2];

    //Apply second and fourth order radial distortion.
    const T& l1 = camera[7];
    const T& l2 = camera[8];
    const T r2 = xp*xp + yp*yp;
    const T distortion = 1.0 + r2  * (l1 + l2  *r2);


    //Compute final projected point position.
    const T& focal = camera[6];
    const T predicted_x = focal * distortion *xp;
    const T predicted_y = focal * distortion *yp;

    //The error is the difference between the predicted and observed position.
    residuals[0] = predicted_x -observed_x;
    residuals[1] = predicted_y -observed_y;

    return true;
  }

  //Factory to hide the construction of the CostFunction object from
  //the client code.
  static ceres::CostFunction* Create(const doubleobserved_x,
                                     const doubleobserved_y) {
    return (new ceres::AutoDiffCostFunction<SnavelyReprojectionError, 2, 9, 3>(
                newSnavelyReprojectionError(observed_x, observed_y)));
  }

  doubleobserved_x;
  doubleobserved_y;
};

//Templated pinhole camera model for used with Ceres.  The camera is
//parameterized using 10 parameters. 4 for rotation, 3 for
//translation, 1 for focal length and 2 for radial distortion. The
//principal point is not modeled (i.e. it is assumed be located at
//the image center).
structSnavelyReprojectionErrorWithQuaternions {
  //(u, v): the position of the observation with respect to the image
  //center point.
  SnavelyReprojectionErrorWithQuaternions(double observed_x, doubleobserved_y)
      : observed_x(observed_x), observed_y(observed_y) {}

  template <typename T>
  bool operator()(const T* constcamera,
                  const T* constpoint,
                  T* residuals) const{
    //camera[0,1,2,3] is are the rotation of the camera as a quaternion.
    //
    //We use QuaternionRotatePoint as it does not assume that the
    //quaternion is normalized, since one of the ways to run the
    //bundle adjuster is to let Ceres optimize all 4 quaternion
    //parameters without a local parameterization.
    T p[3];
    QuaternionRotatePoint(camera, point, p);

    p[0] += camera[4];
    p[1] += camera[5];
    p[2] += camera[6];

    //Compute the center of distortion. The sign change comes from
    //the camera model that Noah Snavely's Bundler assumes, whereby
    //the camera coordinate system has a negative z axis.
    const T xp = - p[0] / p[2];   //x/z
    const T yp = - p[1] / p[2];    //y/z

    //Apply second and fourth order radial distortion.
    const T& l1 = camera[8];
    const T& l2 = camera[9];

    const T r2 = xp*xp + yp*yp;
    const T distortion = 1.0 + r2  * (l1 + l2  *r2);

    //Compute final projected point position.
    const T& focal = camera[7];
    const T predicted_x = focal * distortion *xp;
    const T predicted_y = focal * distortion *yp;

    //The error is the difference between the predicted and observed position.
    residuals[0] = predicted_x -observed_x;
    residuals[1] = predicted_y -observed_y;

    return true;
  }

  //Factory to hide the construction of the CostFunction object from
  //the client code.
  static ceres::CostFunction* Create(const doubleobserved_x,
                                     const doubleobserved_y) {
    return (new ceres::AutoDiffCostFunction<SnavelyReprojectionErrorWithQuaternions, 2, 10, 3>(
                newSnavelyReprojectionErrorWithQuaternions(observed_x,
                                                            observed_y)));
  }

  doubleobserved_x;
  doubleobserved_y;
};

免责声明:文章转载自《ceres---相机重投影误差》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇PyCharm撤消/恢复iOS CAShapeLayer精讲下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Haskell语言学习笔记(23)MonadReader, Reader, ReaderT

MonadReader 类型类 class Monad m => MonadReader r m | m -> r where ask :: m r ask = reader id local :: (r -> r) -> m a -> m a reader :: (r -> a)...

程序破解之 API HOOK技术 z

API HOOK,就是截获API调用的技术,在程序对一个API调用之前先执行你的函数,然后根据你的需要可以执行缺省的API调用或者进行其他处理,假设如果想截获一个进程对网络的访问,一般是几个socket API : recv,recvfrom, send, sendto等等,当然你可以用网络抓包工具,这里只介绍通过API HOOK的方式来实现, 主要原理是...

常用ES6语法

1.let和const let和const在块级作用域内有效,不会污染全局变量,都存在暂时性死区,只能先声明再使用,且不能重复声明 const声明的是常量(指的是常量对应的内存地址不得改变),必须赋值,只读,但对于对象、数组,里面的值可以改变 let使用经典案例:let命令代替闭包功能 var arr = [] for(var i=0;i<2;i++...

vue 调用本地json配置

在webpack.dev.conf.js文件中 /*----------------jsonServer---------*/ /*引入json-server*/const jsonServer = require('json-server') /*搭建一个server*/const apiServer =jsonServer.create() /*将d...

js数组中的每一项异步请求

数组中的每一个选项,都进行一次异步请求,然后所有请求完成再操作返回值,Promise.all     getInfo = (param) => {         const { getData } = this.props // getData为接口请求         return new Promise(resolve => {    ...

echarts实时数据图表

import React, { PureComponent } from 'react'; import ReactEcharts from 'echarts-for-react'; import moment from 'moment'; export defaultclass Charts extends PureComponent { getO...