I have written a script in python that calls the cv2.minEnclosingCircle method, I am trying to recreate a similar program in c++ but I am not able to pass radius and center by reference.
I have tried to use alternative answers regarding invalid initialisation and to follow the openCV documentation regarding the function but it is not clear, I am able to pass radius and center without the '&' however I would prefer not to.
Here is the docs regarding the method http://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#minenclosingcircle
Here is my code:
if (contours.size() > 0)
{
auto c = *std::max_element(contours.begin(),contours.end(),
[](std::vector<cv::Point> const& lhs, std::vector<cv::Point> const& rhs)
{return contourArea(lhs, false) < contourArea(rhs, false); });
cv::minEnclosingCircle(c, ¢er, &radius); // not compiling
}
I have declared radius and center as a float and cv::Point2f types respectively.
Error: invalid initialization of non-const reference of type 'cv::Point2f& {aka cv::Point_<float>& }' from an rvalue of type 'cv::Point2f* {aka cv::Point_<float>*}
Here is how I do it in Python:
if len(contours) > 0;
#find largest contour in mask, use to compute minEnCircle
c = max(contours, key = cv2.contourArea)
(x,y), radius) = cv2.minEnclosingCircle(c) #not compiling in c++
M = cv2.moments(c)