Skip to content

[GSoC] Update octree methods and create frames for PCC#23985

Merged
asmorkalov merged 32 commits into
opencv:5.xfrom
starga2er777:pcc
Feb 29, 2024
Merged

[GSoC] Update octree methods and create frames for PCC#23985
asmorkalov merged 32 commits into
opencv:5.xfrom
starga2er777:pcc

Conversation

@starga2er777
Copy link
Copy Markdown

PR for GSoC Point Cloud Compression

Issue for GSoC 2023

  • 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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@TsingYiPainter
Copy link
Copy Markdown

@opencv-alalek @asmorkalov, Hi, although I changed the name of the repo (Its name is now opencv, the original name was opencv_contrib) and make a new PR, the build still failed.

pr

As you can see the repo name is still opencv_contrib. How can we do? Should we delete this repo, fork again and submit PR?

@opencv-alalek
Copy link
Copy Markdown
Contributor

Because GitHub keep alias for old repo name.

Try to create empty opencv_contrib repo to reset this alias (and may be delete it after that).

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
* @param maxDepth The max depth of the Octree. The maxDepth > -1.
*/
explicit Octree(int maxDepth);
explicit Octree(size_t maxDepth);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change API w/o any good reason?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I think maxDepth should be non-negative, and part of the subsequent code compares maxDepth to unsigned integers, I adopted this approach to avoid potential problems.

In addition, I forgot to change the corresponding explanation, which is my negligence.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have int here since, among other reasons, it has better compatibility with our wrapper generators for Python and Java.

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
* @param resolution The size of the octree leaf node.
*/
Octree(const std::vector<Point3f> &pointCloud, int maxDepth);
Octree(const std::vector<Point3f> &pointCloud, double resolution);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe both resolution and maxDepth could be specified or one of them; why remove maxDepth?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's reasonable to retain both options.

The resolution denotes the size of the leaf node. I opted for resolution as it aligns well with point cloud compression, where preserving information at this precision is sufficient.

For the current octree functions, such as KNN search, it might be better to retain both methods. Simultaneously, the two can be calculated from one to the other.

What's your opinion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since octree is used not only for point cloud compression, I'd propose you to keep both constructors (resolution and maxDepth)

@vpisarev
Copy link
Copy Markdown
Contributor

@savuor, could you please review it?

@asmorkalov
Copy link
Copy Markdown
Contributor

@savuor Friendly reminder.

@asmorkalov asmorkalov added this to the 5.0 milestone Oct 5, 2023
Copy link
Copy Markdown
Contributor

@savuor savuor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my comments, looks like there are several things to fix

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
* @param resolution The size of the octree leaf node.
*/
Octree(const std::vector<Point3f> &pointCloud, int maxDepth);
Octree(const std::vector<Point3f> &pointCloud, double resolution);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since octree is used not only for point cloud compression, I'd propose you to keep both constructors (resolution and maxDepth)

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
* @param restorePointCloud The output point cloud data.
* @param restoreColor The color attribute of point cloud data
*/
void getPointCloudByOctree(std::vector<Point3f> &restorePointCloud, std::vector<Point3f> &restoreColor);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method calculate an average color for the point in the same leaf?
If not, it should be said explicitly in the docs to the function

Comment thread modules/3d/src/octree.cpp Outdated
}

bool insertPointRecurse( Ptr<OctreeNode>& _node, const Point3f& point, int maxDepth)
bool insertPointRecurse( Ptr<OctreeNode>& _node, const Point3f& point,const Point3f &color, size_t maxDepth,const OctreeKey &key,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this function always returns true, don't need to return anything at all

Comment thread modules/3d/test/test_octree.cpp Outdated
EXPECT_NO_THROW(treeTest.radiusNNSearch(restPoint, radius, outputPoints, outputSquareDist));
EXPECT_EQ(outputPoints.size(),(unsigned int)5);

//The outputPoints should be unordered, so in some resolution, this test will fail because it specified the order of output.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is so, maybe the points should be sorted by distance first?

Comment thread modules/3d/src/pcc.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file belongs to next PR about point cloud compression (probably #24197), should it be here?

@savuor
Copy link
Copy Markdown
Contributor

savuor commented Jan 26, 2024

A decision was to fix this PR by me

@broweigit
Copy link
Copy Markdown

Sorry for the late reply. I'm still here working on this PointCloudCompression commitment since GSOC. We've made a variety of experiment on PCC algorithms but the most significant improvement lies on a structural improvement on the OctreeNode class and the usage of Zlib.
We now hold a functional PCC code developed in OpenCV(and usable, better than PCL, I guess?). Yet I just want you to know that we try to make separate PRs to push limited workload stage by stage.
Looks like some fix have been made. Since you know the exact demand that opencv needs. maybe we shall wait until this PR is stabled, then continue our next part? But if there's anything we can do, please contact us! Thanks.

@broweigit
Copy link
Copy Markdown

Our further PCC code should based on this PR, I shall make some adjustment on latter PCC framwork after you finished. Is it?

@savuor
Copy link
Copy Markdown
Contributor

savuor commented Feb 19, 2024

@broweigit Hi there! I'm trying to fix this PR according to the notes I've made (and according to my personal understand of how this should be done :) ). I will invite you to review the changes I've made, along with other contributors.
Right after this PR is done, I'm going to work on Point Cloud Compression PR (#24197) in the same manner.

@savuor
Copy link
Copy Markdown
Contributor

savuor commented Feb 22, 2024

@broweigit I've changed API and some implementation details, can you take a look?

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
* @param colors color attribute of point cloud in the same 3-channel float format
* @return resulting Octree
*/
static Octree createWithDepth(int maxDepth, InputArray pointCloud, InputArray colors = noArray());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input arrays usually go first in the public API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made intentionally to reduce amount of overloaded methods

Comment thread modules/3d/include/opencv2/3d.hpp Outdated
Comment thread modules/3d/test/test_octree.cpp Outdated
Comment on lines +101 to +106
for (int i = 0; i < (int)goldVals.size(); i++, it++)
{
Point3f p = it->second;
EXPECT_FLOAT_EQ(goldVals[i].x, p.x);
EXPECT_FLOAT_EQ(goldVals[i].y, p.y);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be just NORM_INF

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to leave it as it is, using NORM_INF looks cumbersome here

@broweigit
Copy link
Copy Markdown

@broweigit I've changed API and some implementation details, can you take a look?

Yep, checked. no problem with the changes for far. Thanks

Comment thread modules/3d/src/octree.cpp Outdated
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov
Copy link
Copy Markdown
Contributor

@vpisarev @TsingYiPainter Do you have any remarks?

@asmorkalov asmorkalov merged commit 0e47b05 into opencv:5.x Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants