void TranslateSimpleContour(std::vector<cv::Point> &contour, const int &shiftHorizontal, const int &shiftVertical) // translate simple contour along vertical and/or horizontal axis
{
cv::Point t(shiftHorizontal, shiftVertical);
for (int nb = 0; nb < int(contour.size()); nb++)
contour[nb] += t;
}
How to make it take any cv::Point format like cv::Point2i, cv::Point2f or cv::Point2d in the std::vector ? A “universal” cv::Point2x version of this function…
re my remarks on “const references”: I should have qualified that w.r.t. those int parameters. in other contexts, const references do make sense, not there.
The aim is not to multiply the functions or putting “ifs” in them to care about each type of value. cv::Point_<T> can’t be used for variables in functions, I think it was the first thing I tried.
That looks nice, but it requires a copy of the data each time, not very optimized. I could work with cv::Mats instead of vectors of points though. I’ll try it!
I think, in addition to learning C++ templates as others have suggested, it would be beneficial if you learn how to read the compiled machine code. By doing so, you will understand that, in C++, each type of Point_ (e.g. Point2i, Point2f, etc) requires different machine code to handle.
Since I asked this question I have successfully learned about templates, applied the concept to what I wanted to do, with success. I had a hard time finding the right way to declare in the functions body the other associated variables corresponding to the type of the template (cv::Rect for example), etc.
I’m a fast learner, it’s just that the docs of OpenCV and C++ are difficult to read and understand if you are not accustomed to that kind of litterature. And OpenCV’s doc is sometimes too “light”.
Ah, one last thing : how do I indicate my question was solved ?