Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Add Octree to 3D module in next branch - in progress#19684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
vpisarev commentedMar 26, 2021
@zihaomu, thank you for the contribution and sorry for delay with the review.
|
zihaomu commentedMar 29, 2021
@vpisarev Thank you for your suggestion, I will continue to work on it. |
asenyaev commentedApr 8, 2021
jenkins cn please retry a build |
zihaomu commentedApr 8, 2021
Hi@asenyaev. Thank you for your reminder, how to retry a build? |
asenyaev commentedApr 8, 2021
Hi@zihaomu. The command is the same as my latest comment. |
zihaomu commentedMay 16, 2021
alalek left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for updates!
Please take a look on the comments below.
BTW,cv::Ptr-based implementation is not efficient from time or memory consumption metrics. RGB-D cameras may provide 1M points for each frame.
Are there plans to support points "metadata" in some form?
/cc@savuor
modules/3d/include/opencv2/3d.hpp Outdated
| children[6]: origin == (0, 1, 1), size == 1, in Y-Z plane | ||
| children[7]: origin == (1, 1, 1), size == 1, furthest from child 0 | ||
| */ | ||
| classOctree { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
CV_EXPORTS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for your code review. Currently, Octree to Python has not been completed, so "CV_EXPORTS" is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
CV_EXPORTS
is not the same asCV_EXPORTS_W
This change is required. Also this would allow to remove hacks from the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@alalek Thank you for your reminder, I have added the "CV_EXPORT" flag in the new version.
modules/3d/include/opencv2/3d.hpp Outdated
| voidclear(); | ||
| voidstep(); | ||
| enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
remove unnecessary changes from the patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
modules/3d/include/opencv2/3d.hpp Outdated
| /** @overload | ||
| * @brief Create an empty Octree and set the maximum depth. | ||
| * @param _maxDepth The max depth of the Octree. The _maxDepth > -1. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Something is wrong with indentation
modules/3d/include/opencv2/3d.hpp Outdated
| * @brief Create an empty Octree and set the maximum depth. | ||
| * @param _maxDepth The max depth of the Octree. The _maxDepth > -1. | ||
| */ | ||
| Octree(int _maxDepth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Avoid using underscore prefixes in public headers.
We don't need them in the public API.
BTW, C++ allows to use any name for parameters in .cpp file (but it should correlate with name in .hpp to keep code readable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, this will be fixed in the new version.
modules/3d/include/opencv2/3d.hpp Outdated
| boolempty(); | ||
| /** @brief | ||
| * Reset all octree parameterDeleting a point from the octree actually deletes the corresponding element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
parameterDeleting
what is that?
Please re-read documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
modules/3d/src/octree.hpp Outdated
| namespacecv { | ||
| //! @addtogroup 3d | ||
| //! @{ | ||
| /** @brief OctreeNode for Octree. | ||
| The class OctreeNode represents the node of the octree. Each node contains 8 children, which are used to divide the | ||
| space cube into eight parts. Each octree node represents a cube. | ||
| And these eight children will have a fixed order, the order is described as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Avoid indentation in namespaces.
modules/3d/test/test_octree.cpp Outdated
| TEST_F(OctreeTest, BasicFunctionTest) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
unnecessary indentation
modules/3d/test/test_octree.cpp Outdated
| { | ||
| int K =4; | ||
| std::vector<Point3f> outputPoints; | ||
| std::vector<float> outputSquareDist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
missing indentation
modules/3d/test/test_octree.cpp Outdated
| { | ||
| float _x = rng_Point.uniform(pmin.x, pmax.x); | ||
| float _y = rng_Point.uniform(pmin.y, pmax.y); | ||
| float _z = rng_Point.uniform(pmin.z, pmax.z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
BTW, floating-point random numbers are not bit-exact between platforms.
modules/3d/test/test_octree.cpp Outdated
| pmin =Point3f(-1.0f, -1.0f, -1.0f); | ||
| pmax =Point3f(1.0f,1.0f,1.0f); | ||
| RNGrng_Point(12345);// set random seed for fixing output 3D point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OpenCV testing infrastructure should "fix"theRNG() state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@zihaomu, please, removerng_Point from the class.
Before the point cloud initialization loop simply put
RNG& rng_Point = theRNG();modules/3d/test/test_octree.cpp Outdated
| // Generate 3D PointCloud | ||
| for (int i =0; i < pointCloudSize; i++) | ||
| { | ||
| float _x = rng_Point.uniform(pmin.x, pmax.x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@zihaomu, I suggest to use integer pmin & pmax and then inside the loop scale it by a power-of-two, then we can guarantee bit-exactness between platforms:
int scale;Point3i pmin, pmax;....scale = 1<<20;pmin = Point3i(-scale, -scale, -scale);pmax = Point3i(scale, scale, scale);...RNG rng_Point(12345);for(int i = 0; i , pointCloudSize; i++){ float _x = (float)rng_Point.uniform(pmin.x, pmax.x)/scale; float _y = (float)rng_Point.uniform(pmin.y, pmax.y)/scale; float _z = (float)rng_Point.uniform(pmin.z, pmax.z)/scale; pointcloud.push_back(Point3f(_x, _y, _z));}modules/3d/src/octree.hpp Outdated
| // | ||
| // License Agreement | ||
| // For Open Source Computer Vision Library | ||
| // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please align license headers in both files fromsrc/ directory (they should have the same content).
Consider using this form:
// 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.then add this if required:
//// Copyright (C) 2021, Huawei Technologies Co., Ltd. All rights reserved.// Third party copyrights are property of their respective owners.And optionally add this:
//// Author: Zihao Mu <zihaomu6@gmail.com>// Liangqian Kong <chargerKong@126.com>// Longbu Wang <riskiest@gmail.com>modules/3d/src/octree.hpp Outdated
| // Longbu Wang <riskiest@gmail.com> | ||
| #ifndef OPENCV_OCTREE_OCTREE_H | ||
| #defineOPENCV_OCTREE_OCTREE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OPENCV_OCTREE_OCTREE_H
OPENCV_3D_SRC_OCTREE_HPP (OPENCV_<module_name>_<file_path_name>_HPP)
modules/3d/src/octree.hpp Outdated
| constfloat epsilon = std::numeric_limits<float>::epsilon();// For precision of floating point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
used?
If so, then replace withstd::numeric_limits<float>::epsilon() directly.
modules/3d/src/octree.hpp Outdated
| conststaticint octreeChildNum =8;// Each OctreeNode contains up to 8 children. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Put global constant intoOctreeNode class (probably as enum value).
| #include"octree.hpp" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
octree.hpp
Do we need dedicatedsrc/octree.hpp file? (it makes sense to put all details in this .cpp file)
modules/3d/test/test_octree.cpp Outdated
| usingnamespacecv; | ||
| classOctreeTest:public::testing::Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
public<space>
modules/3d/test/test_octree.cpp Outdated
| std::vector<float> outputSquareDist; | ||
| EXPECT_NO_THROW(octreeRadiusNNSearch(treeTest, restPoint, radius, outputPoints, outputSquareDist)); | ||
| EXPECT_NEAR(outputPoints[0].x, -0.888461112976f, std::numeric_limits<float>::epsilon()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
EXPECT_FLOAT_EQ()?
modules/3d/test/test_octree.cpp Outdated
| { | ||
| // Check if the point in Bound. | ||
| EXPECT_EQ(treeTest.isPointInBound(restPoint),true); | ||
| EXPECT_EQ(treeTest.isPointInBound(restPoint +Point3f(2,2,2)),false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
EXPECT_TRUE()EXPECT_FALSE()
here and below with true/false
modules/3d/src/octree.cpp Outdated
| Ptr<OctreeNode>index(const Point3f& point, Ptr<OctreeNode>& node) | ||
| { | ||
| if(node ==nullptr) | ||
| { | ||
| returnnullptr; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
node == nullptrcomparison is not efficient. Useoperator boolinstead.return nullptr;is not efficient.- reduce amount of
node->dereferences.
Ptr<OctreeNode> index(const Point3f& point, Ptr<OctreeNode>& node_){ if (!node_) { return Ptr<OctreeNode>(); } OctreeNode& node = *node_; ...}Probably you don't needPtr<> in this implementation.
Ptr<OctreeNode> index(const Point3f& point, const OctreeNode& node)modules/3d/include/opencv2/3d.hpp Outdated
| /** @brief Octree for 3D vision. | ||
| In 3D vision filed, the Octree is used to process and accelerate the pointcloud data. The class Octree represents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
empty line after@brief note:http://pullrequest.opencv.org/buildbot/export/pr/19684/docs/d3/da6/classcv_1_1Octree.html
alalek left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for update!
modules/3d/src/octree.hpp Outdated
| #ifndef OPENCV_3D_SRC_OCTREE_HPP | ||
| #defineOPENCV_3D_SRC_OCTREE_HPP | ||
| #include"precomp.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
precomp.hpp
should be used by .cpp files only (as first include)
modules/3d/include/opencv2/3d.hpp Outdated
| * @param maxDepth The max depth of the Octree. | ||
| * @return Returns whether the creation is successful. | ||
| */ | ||
| boolcreat(const std::vector<Point3f> &pointCloud,int maxDepth = -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
creat
create
modules/3d/src/octree.cpp Outdated
| // Locate the OctreeNode corresponding to the input point from the given OctreeNode. | ||
| Ptr<OctreeNode>index(const Point3f& point, Ptr<OctreeNode>& node); | ||
| bool_isPointInBound(const Point3f& _point,const Point3f& _origin,double _size); | ||
| voidinsertPointRecurse( Ptr<OctreeNode>& node,const Point3f& point,int maxDepth); | ||
| booldeletePointRecurse( Ptr<OctreeNode>& node); | ||
| // For Nearest neighbor search. | ||
| floatSquaredDistance(const Point3f& query,const Point3f& origin); | ||
| booloverlap(const OctreeNode& node,const Point3f& query,float squareRadius); | ||
| template<typename T>structPQueueElem;// Priority queue | ||
| voidradiusNNSearchRecurse(const Ptr<OctreeNode>& node,const Point3f& query,float squareRadius, | ||
| std::vector<PQueueElem<Point3f>>& candidatePoint); | ||
| voidKNNSearchRecurse(const Ptr<OctreeNode>& node,const Point3f& query,constint K, | ||
| float& smallestDist, std::vector<PQueueElem<Point3f>>& candidatePoint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
These declarations should be local - usestatic for that.
Also some declaration can be removed (used after declaration) - addstatic to definition only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for your carefully reviewing. I have addedstatic prefix in these functions.
9fc54fd toae07a9eComparevpisarev commentedJun 8, 2021
@zihaomu, thank you! Could you, please, squash the commits into 1? |
vpisarev commentedJun 8, 2021
@zihaomu, for some reason, there is merge conflict after squash |
vpisarev commentedJun 8, 2021
@zihaomu, check the PR more carefully. Now it shows that 1297 files are changed. There is something wrong |
zihaomu commentedJun 8, 2021
Thank you, I'm checking it now. |
alalek commentedJun 19, 2021
Valgrind builder reports about memory leaks from octree code:http://pullrequest.opencv.org/buildbot/builders/5_x_valgrind-lin64-debug/builds/10 |
zihaomu commentedJun 19, 2021
Thank you for pointing out this. I will keep work on it. |
Uh oh!
There was an error while loading.Please reload this page.
Add Octree to 3D module in next branch - in progress
Hi, recently we want to contribute an
octreeclass to thenextbranch. We read some implementations in open source projects, such as Open3D, PCL, Octomap. They all contain octrees, but their implementation is different.In the current PR, we have only implemented some very basic functions.
Before improving it, we have the following doubts:
nextbranch should be implemented?octreein the3dmodule in the future?Looking forward to your opinion, thank you.
The
viz-based visualization examples can be found athere.Pull Request Readiness Checklist
See details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.