点云参考软件pcc的帧内编码函数解析

          pcl_codec模块:

1. 进入mian()函数,调用encode函数对点云帧进行编码。

                 encode ( inFile, outFile, codecParams );

      infile表示输ply入文件,outfile 表示输出pcc文件,codecParams表示编码参数。

2.进入encode函数,调用两个主要的函数;

            loadPLY ( inFile, pointSet, NULL );//加载ply文件;
         encodeData ( pointSet, encodedData, codecParams );//进行编码的主体函数;

 3.进入encodeDaTa();

   pcl::fromPCLPointCloud2 ( mesh.cloud, *l_ptr );//将mesh.cloud中的数据加载到到l_ptr中;

  #if __cplusplus >= 201103L
         auto l_codec_encoder = generatePCLOctreeCodecV2<PointXYZRGB> (
 #else
         boost::shared_ptr<OctreePointCloudCodecV2<PointXYZRGB> > l_codec_encoder = generatePCLOctreeCodecV2<PointXYZRGB> (
 #endif//__cplusplus < 201103L
          codecParams->octreeBits,
          codecParams->enhBits,
          codecParams->colorBits,
          codecParams->dunno,
          codecParams->colorCodingType,
          codecParams->keepCentroid
          );//只是设置了一些参数;
 tt.tic ();
 l_codec_encoder->encodePointCloud ( l_ptr ,l_output_base);//真正的编码点云的函数,哈哈哈;

4.进入encodePointCloud();

deleteCurrentBuffer();
      deleteTree();

      // initialize octree
      setInputCloud (cloud_arg);

      // CWI added, when encoding hte output variable stores the (simplified icloud)
      output_ = PointCloudPtr(new PointCloud());

      // add point to octree
      addPointsFromInputCloud ();//构建八叉树的主函数,将ply文件中的一个个点按照坐标放进八叉树中,八叉树是由一个个体素组成的;

      // make sure cloud contains points
      if (leaf_count_>0) {

        // color field analysis
        cloud_with_color_ = false;
        std::vector<pcl::PCLPointField> fields;
        int rgba_index = -1;
        rgba_index = pcl::getFieldIndex (*input_, "rgb", fields);
        if (rgba_index == -1)
        {
          rgba_index = pcl::getFieldIndex (*input_, "rgba", fields);
        }
        if (rgba_index >= 0)
        {
          point_color_offset_ = static_cast<unsigned char> (fields[rgba_index].offset);
          cloud_with_color_ = true;
        }

        // apply encoding configuration
        cloud_with_color_ &= do_color_encoding_;

        // if octree depth changed, we enforce I-frame encoding
        i_frame_ |= (recent_tree_depth != getTreeDepth ());// | !(iFrameCounter%10);

        // enable I-frame rate
        if (i_frame_counter_++==i_frame_rate_)
        {
          i_frame_counter_ =0;
          i_frame_ = true;
        }

        // increase frameID
        frame_ID_++;

        // do octree encoding
        if (!do_voxel_grid_enDecoding_)
        {
          point_count_data_vector_.clear ();
          point_count_data_vector_.reserve (cloud_arg->points.size ());
        }

        // initialize color encoding (including new color coding based on jpeg)
        if(!color_coding_type_){
          color_coder_.initializeEncoding ();
          color_coder_.setPointCount (static_cast<unsigned int> (cloud_arg->points.size ()));
          color_coder_.setVoxelCount (static_cast<unsigned int> (leaf_count_));
        }else
        { // new jpeg color coding
          jp_color_coder_.initializeEncoding ();//初始化就是清空;
          jp_color_coder_.setPointCount (static_cast<unsigned int> (cloud_arg->points.size ()));
          jp_color_coder_.setVoxelCount (static_cast<unsigned int> (leaf_count_));
        }
        // initialize point encoding (including new centroid encoder)
        point_coder_.initializeEncoding ();
        centroid_coder_.initializeEncoding ();
        point_coder_.setPointCount (static_cast<unsigned int> (cloud_arg->points.size ()));
        centroid_coder_.initializeEncoding ();
        centroid_coder_.setPointCount( static_cast<unsigned int> (object_count_));

        // serialize octree
        if (i_frame_)
          // i-frame encoding - encode tree structure without referencing previous buffer
          serializeTree (binary_tree_data_vector_, false);//构建完八叉树后,对八叉树进行处理,一是深度优先遍历得到八叉树结构的一维表示,二是计算八叉树中的每个体素的质心来表示体素,并计算质心与每个体素左下角坐标计算差分值;三是计算每个体素内所有点的颜色均值;
        else
          // p-frame encoding - XOR encoded tree structure
          serializeTree (binary_tree_data_vector_, true);


        // write frame header information to stream
        writeFrameHeader (compressed_tree_data_out_arg);//写头信息;

        // apply entropy coding to the content of all data vectors and send data to output stream
        entropyEncoding(compressed_tree_data_out_arg, compressed_tree_data_out_arg);//对上面说的三部分数据进行熵编码,用的方法是range  coding,编码完成后得到三个数据,一个是表示八叉树结构的,一个是表示每个体素质心的,一个是每个体素的颜色均值,然后把这些数据加上一些头信息传给解码端就可以进行解码。

 


  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值