leomariga/pyRANSAC-3D

Restrict Volume of Cuboid

Closed this issue · 2 comments

Thank you very much for this repo! I learned a lot form it and enjoyed working with it.

Do you know if it is possible to restrict the solution of the cuboid by imposing a known volume (or width, height, lenght) or the cuboid? I use the cuboid.fit algorithm on a pointcloud containing multiple objects. Unfortunately, the algorithm returned a cuboid that returned a solution comprising all distinct object. I tried to restrict the algorithm as followes:

lenght = pts[pt_id_inliers, 0].max() - pts[pt_id_inliers, 0].min()
height = pts[pt_id_inliers, 1].max() - pts[pt_id_inliers, 1].min()
width = pts[pt_id_inliers, 2].max() - pts[pt_id_inliers, 2].min()
volume = height * length * width
if volume > max_volume:
    continue

Where max_volume is a function argument to the fit function. Strangely, the proposed solution of the algorithm does not change from one iteration to the loop to the other and at the end the algorithm does not find any solution.

Do yo have any idea how one could impose a restricted size of the cuboid?

Hi Fabian, nice to hear you are trying new things in pyRANSAC3D library =)

Restricting the volume from a cuboid seems to be a simple mathematical problem, but for most cases it isn't. Your solution as you presented above will only work if the faces of the cuboid are perfectly aligned to the inertial frame (the length of the cuboid is in the X axis, for example). If this condition is not met, you will measure a 3d kind-of-diagonal of the cuboid which will definitely give you the wrong volume.

The problem you are facing can be solved with minimum bounded rectangle (MBR) (https://en.wikipedia.org/wiki/Minimum_bounding_rectangle) algorithm or, in your case, minimum volume cuboid. A possible way to solve is to make a projection of the points with the candidate plane equation, and transform this in a 2d problem which can apply a MBR algorithm to calculate the width and height of a rectangle. Using the three different dimensions from this algorithm you can calculate its approximate volume.

There might be other solutions such as working with the face's equation to rotate the cuboid to the inertial frame but it seems to be more complicated. I recomend the MBR algorithm by dbworth to start with:

https://github.com/dbworth/minimum-area-bounding-rectangle

Thanks, Leonardo for your kind and informative reply! Your explanation for why specifying volumes is not that straightforward makes a lot of sense. I am trying to look a bit more into the MBR and also into other possibilities.