Cedric Cedric - 2 months ago 4x
C++ Question

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

I am trying to emplace_back a locally constructed (inside method)

onto an object variable (declared as
). 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

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?



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.