当前位置: 首页>>代码示例>>C++>>正文


C++ Pyramid::ExpandFloat方法代码示例

本文整理汇总了C++中Pyramid::ExpandFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ Pyramid::ExpandFloat方法的具体用法?C++ Pyramid::ExpandFloat怎么用?C++ Pyramid::ExpandFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pyramid的用法示例。


在下文中一共展示了Pyramid::ExpandFloat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

/**
 * @function main
 */
int main( int argc, char* argv[] ) {

    /// Read image
    if( argc < 3 )
    { printf("You moron! I need at least two images \n"); return -1; }

    /// Load images as they are
    cv::Mat L = cv::imread( argv[1], -1 );
    cv::Mat R = cv::imread( argv[2], -1 );
  
    // Have ready my Pyramid  and LK object
    Pyramid pyr;
    LK lk;

    // Hierarchical LK
    int n = 4; // Max level 
    int k;

    // Get the required pyramid levels
    std::vector<cv::Mat> PL(n+1);
    std::vector<cv::Mat> PR(n+1);

    PL[0] = L.clone();
    PR[0] = R.clone();

    for( int i = 1; i <= n; i++ ) {
      PL[i] = pyr.Reduce( PL[i-1] );
      PR[i] = pyr.Reduce( PR[i-1] );
    }

    /// Let's start the real thing
    cv::Mat Lk, Rk;
    cv::Mat U, V;
    cv::Mat Dx, Dy; 
    cv::Mat Wk;
    cv::Mat Wkg, Rkg, Lkg;

    /// 1. Initialize k = n
    k = n;

    while( k >= 0 ) {

      /// 2. Reduce both images to level k
      Lk = PL[k]; 
      Rk = PR[k]; 

      /// 3. If k = n initialize U and K to zeros of the size of Lk 
      if( k == n ) {
          U = cv::Mat::zeros( Lk.size(), CV_32FC1 );
          V = cv::Mat::zeros( Lk.size(), CV_32FC1 );
      }
      /// Else expand the flow field and double it
      else {
          cv::Mat tempU, tempV;
          tempU = pyr.ExpandFloat(U);
          tempV = pyr.ExpandFloat(V);

          U = cv::Mat( tempU.size(), CV_32FC1 );
          V = cv::Mat( tempV.size(), CV_32FC1 );

          for( int j = 0; j < U.rows; j++ )
          { for( int i = 0; i < U.cols; i++ )
            {
               U.at<float>(j,i) = ( 2.0*tempU.at<float>(j,i) );
               V.at<float>(j,i) = ( 2.0*tempV.at<float>(j,i) );
            }
          }
      }

      /// 4. Warp Lk using U and V to form Wk
      Wk = lk.Remap2to1( Rk, U, V );
      char buf[30];
      sprintf( buf, "Wk%d.png", k);
      imwrite( buf, Wk );

      /// 5. Perform LK on Wk and Rk
      cvtColor( Wk, Wkg, CV_BGR2GRAY );
      cvtColor( Lk, Lkg, CV_BGR2GRAY );
      cvtColor( Rk, Rkg, CV_BGR2GRAY );

      //lk.OpticFlowEstimation1( Lkg, Wkg, Dx, Dy, 2.0 );
      //lk.OpticFlowEstimation3( Lkg, Wkg, Dx, Dy, 2.0 );
   
      /// 6. Add these to the original flow
      for( int j = 0; j < U.rows; j++ )
      { for( int i = 0; i < U.cols; i++ )
        {
           U.at<float>(j,i) = U.at<float>(j,i) + Dx.at<float>(j,i);
           V.at<float>(j,i) = V.at<float>(j,i) + Dy.at<float>(j,i);
        }
      }

      cv::Mat temp = lk.Remap2to1( Rk, U, V );
      sprintf( buf, "Wk%dend.png", k);
      imwrite( buf, temp );   

      k = k - 1;
//.........这里部分代码省略.........
开发者ID:ana-GT,项目名称:CVHacking,代码行数:101,代码来源:proj5-3-1.cpp


注:本文中的Pyramid::ExpandFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。