opencv/modules/3d/src/pcc.h

95 lines
2.8 KiB
C
Raw Normal View History

Merge pull request #23985 from starga2er777:pcc [GSoC] Update octree methods and create frames for PCC #23985 ## PR for GSoC Point Cloud Compression [Issue for GSoC 2023](https://github.com/opencv/opencv/issues/23624) * We are **updating the Octree method create() by using OctreeKey**: Through voxelization, directly calculate the leaf nodes that the point cloud belongs to, and omit the judgment whether the point cloud is in the range when inserted. The index of the child node is calculated by bit operation. * We are also **introducing a new header file pcc.h (Point Cloud Compression) with API framework**. * We added tests for restoring point clouds from an octree. * Currently, the features related to octree creation and point cloud compression are part of the internal API, which means they are not directly accessible to users. However, our plan for the future is to **include only the 'PointCloudCompression' class in the 'opencv2/3d.hpp' header file**. This will provide an interface for utilizing the point cloud compression functionality. The previous PR of this was closed due to repo name conflicts, therefore we resubmitted in this PR. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
2024-02-29 19:02:44 +08:00
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Author: Yuhang Wang <yuhangwang0012@gmail.com>
// Chengwei Ye <broweigg@gmail.com>
// Zhangjie Cheng <zhangjiec01@gmail.com>
#ifndef OPENCV_PCC_H
#define OPENCV_PCC_H
#include <vector>
#include "opencv2/core.hpp"
#include "octree.hpp"
#include "opencv2/3d.hpp"
namespace cv {
/** @brief class to serialize or deserialize pointcloud data
*
* A class for "encoding" pointcloud data to a
* meaningful, unevenly distributed char vector,
* so that it can be further compressed by Entropy coding.
* And the opposite "decoding" way as well.
*
* The current implementation is to represent pointcloud as Octree,
* then traverse OctreeNodes to get vector of "occupancy code".
*/
class OctreeSerializeCoder {
private:
Octree *octree;
float resolution;
public:
OctreeSerializeCoder();
OctreeSerializeCoder(float resolution);
//! encode Pointcloud data to serialized char vector
void encode(const std::vector<Point3f> &pointCloud,
std::vector<unsigned char> &serializedVector);
//! decode Pointcloud data from serialized char vector
void decode(const std::vector<unsigned char> &serializedVector,
std::vector<Point3f> &pointCloud);
};
/** @brief Class to reduce vectorized data size by EntropyCoding
*
* The algorithm used here is Range Coding Algorithm.
*
*/
class EntropyCoder {
public:
//! encode char vector to bit stream
void encodeCharVectorToStream(const std::vector<unsigned char> &inputCharVector,
std::ostream &outputStream);
//! decode char vector from bit stream
void decodeStreamToCharVector(const std::istream &inputStream,
std::vector<unsigned char> &outputCharVector);
};
/** @brief pointcloud compression class
*
* This class enables user to do compression and decompression to pointcloud,
* currently based on Octree,
* may support other method (like kd-tree, etc.) in future if necessary.
*
*/
class PointCloudCompression{
private:
OctreeSerializeCoder _coder;
EntropyCoder _entropyCoder;
public:
/** @brief User compress the pointcloud to stream
*
* @param pointCloud the pointcloud to compress
* @param outputStream the output compressed bit stream destination
*/
void compress(const std::vector<Point3f> &pointCloud, std::ostream &outputStream);
/** @brief User decompress(recover) pointcloud from stream
*
* @param inputStream the input compressed bit stream source
* @param pointCloud the output pointcloud
*/
void decompress(std::istream &inputStream, const std::vector<Point3f> &pointCloud);
};
}
#endif //OPENCV_PCC_H