Cedric
Cedric

Reputation: 899

OpenCV vector<point> - No matching contractor for initialization of 'cv::Point_<int>'

I am trying to emplace_back a locally constructed (inside method) cv::Point3i onto an object variable (declared as std::vector<cv::Point>). Doing so, I get the compile error (not runtime):

memory - No matching constructor for initialization of 'cv::Point_<int>'

Trying the same thing with a Point2i instead (omitting one of the value I need), the compiler throws no error.

Here's the snippet from the .cpp file:

void ObjectDetector::centroids2Dto3D() {
    const int* map_ptr = (int*)mapHeight.data;
    unsigned long steps[2];
    steps[0] = mapHeight.step1(0);
    steps[1] = mapHeight.step1(1);
    for (std::vector<cv::Point>::iterator it = centroidsXZ.begin(); it != centroidsXZ.end(); it++) {
        const int x = (*it).x;
        const int z = (*it).y;
        int y = map_ptr[steps[0] * x + steps[1] * z];

        // MARK: The following line causes the error. Without it, the program compiles fine
        centroids.emplace_back(cv::Point3i(x,y,z));
    }
}

As I am not the best at debugging C++, I tend to put the fault on my coding, but I cannot find the problem here.

Could someone points me to a solution or a path toward it?

Thanks!

Upvotes: 0

Views: 1102

Answers (1)

Miki
Miki

Reputation: 41765

Since you're inserting into the vector objects of type cv::Point3i, then the type of centroids should be: std::vector<cv::Point3i>.

Also, you're calling emplace_back wrong. Its arguments should be the arguments to forward to the constructor of the Point3i, i.e.: centroids.emplace_back(x,y,z);

Using emplace_back will avoid the extra copy or move operation required when using push_back. You can find more details here.

Upvotes: 2

Related Questions