opencvopencv-contrib

ICP::registerModelToScene() fails to run minimum example


Here is a minimal example of calling registerModelToScene(), enclosed in class cv::ppf_match_3d::ICP of the OpenCV contribution module surface matching:

#include <opencv2/surface_matching/icp.hpp>
#include <opencv2/surface_matching/ppf_helpers.hpp>

int main() {
    /* allocate solver */
    cv::ppf_match_3d::ICP iterativeClosestPoint;
    
    /* reference vertices */
    cv::Mat reference = cv::ppf_match_3d::loadPLYSimple("reference.ply", 1);
    /* measured vertices */
    cv::Mat measurement = cv::ppf_match_3d::loadPLYSimple("measurement.ply", 1);
    
    /* do the magic */
    double error;
    cv::Matx44d transformation;
    iterativeClosestPoint.registerModelToScene(reference, measurement, error, transformation);

    return 0;
}

The vertices to match against (reference.ply) are given in Polygon File Format, and just represent two points with normals:

ply
format ascii 1.0
element vertex 2
property float x
property float y
property float z
property float nx
property float ny
property float nz
end_header
0 0 0 0 0 1
0 1 0 0 0 1

The vertices that need to be matched are given in the same file format, the same two points, rotated 20° about the z-axis:

ply
format ascii 1.0
element vertex 2
property float x
property float y
property float z
property float nx
property float ny
property float nz
end_header
0 0 0 0 0 1
0.3429 0.93937 0 0 0 1

Code compiles on GCC 8.2.0, OpenCV version 4.0.0.

Runtime error:

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.0.0) Error: Assertion failed (dataset.type() == CvType<ElementType>::type()) in GenericIndex, file C:/Users/maxherrman/openCV/4.0.0/modules/flann/include/opencv2/flann.hpp, line 316

On answers.opencv.org, there is a post stating that the elements' datatypes of the first two parameters of registerModelToScene() (Mat) need to match the ones from the fourth (Matx44d).

But the documenation says:

Currently, CV_32F is the only supported data type.

So the datatype of the elements of model and scene (CV_32F) do not match the datatype of the elements in the pose (double).

Any idea how to circumvent this problem, or did I get things wrong?


Solution

  • you don't have enough data for the algorithm even though the error doesn't state that