Ask Your Question
0

call of overloaded ‘Point_(cv::Point2f&)’ is ambiguous

asked 2013-08-05 13:01:07 -0600

Nenad Bulatovic gravatar image

I am working on some example code for OpenCV2 & C++ and I got stuck. Compiler (MinGW, g++ 4.7.2 on Win7) says that call of overloaded ‘Point_(cv::Point2f&)’ is ambiguous but I can't find exatcly what is wrong. Here is error:

19:53:36 **** Incremental Build of configuration Debug for project Blobs ****
Info: Internal Builder is used for build
g++ "-IC:\\OpenCV246PC\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o blobs.o "..\\blobs.cpp" 
..\blobs.cpp: In function ‘int main()’:
..\blobs.cpp:48:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
..\blobs.cpp:48:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
..\blobs.cpp:84:37: error: call of overloaded ‘Point_(cv::Point2f&)’ is ambiguous
..\blobs.cpp:84:37: note: candidates are:
In file included from ..\blobs.cpp:3:0:
C:\OpenCV246PC\build\include/opencv2/core/core.hpp:740:5: note: cv::Point_<_Tp>::Point_(const CvPoint2D32f&) [with _Tp = int; CvPoint2D32f = CvPoint2D32f]
C:\OpenCV246PC\build\include/opencv2/core/core.hpp:739:5: note: cv::Point_<_Tp>::Point_(const CvPoint&) [with _Tp = int; CvPoint = CvPoint]
C:\OpenCV246PC\build\include/opencv2/core/core.hpp:738:5: note: cv::Point_<_Tp>::Point_(const cv::Point_<_Tp>&) [with _Tp = int; cv::Point_<_Tp> = cv::Point_<int>]

And here is the code:

#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main()
{
    // Read input binary image
    cv::Mat image = cv::imread("binaryGroup.bmp", 0);
    if (!image.data)
        return 0;

    cv::namedWindow("Binary Image");
    cv::imshow("Binary Image", image);

    // Get the contours of the connected components
    std::vector<std::vector<cv::Point> > contours;
    cv::findContours(image, contours, // a vector of contours
            CV_RETR_EXTERNAL, // retrieve the external contours
            CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours

    // Print contours' length
    std::cout << "Contours: " << contours.size() << std::endl;
    std::vector<std::vector<cv::Point> >::const_iterator itContours = contours.begin();
    for (; itContours != contours.end(); ++itContours)
    {

        std::cout << "Size: " << itContours->size() << std::endl;
    }

    // draw black contours on white image
    cv::Mat result(image.size(), CV_8U, cv::Scalar(255));
    cv::drawContours(result, contours, -1, // draw all contours
            cv::Scalar(0), // in black
            2); // with a thickness of 2

    cv::namedWindow("Contours");
    cv::imshow("Contours", result);

    // Eliminate too short or too long contours
    int cmin = 100;  // minimum contour length
    int cmax = 1000; // maximum contour length
    std::vector<std::vector<cv::Point> >::iterator itc = contours.begin();
    while (itc != contours.end())
    {

        if (itc->size() < cmin || itc->size() > cmax)
            itc = contours.erase(itc);
        else
            ++itc;
    }

    // draw contours on the original image
    cv::Mat original = cv::imread("group.jpg");
    cv::drawContours(original, contours, -1, // draw all contours
            cv::Scalar(255, 255, 255), // in white
            2); // with a thickness of 2

    cv::namedWindow("Contours on Animals");
    cv::imshow("Contours on Animals", original);

    // Let's now draw black contours on white image
    result.setTo(cv::Scalar(255));
    cv::drawContours(result, contours, -1, // draw all contours
            cv::Scalar(0), // in black
            1); // with a thickness of 1
    image = cv::imread("binaryGroup.bmp", 0);

    // testing ...
(more)
edit retag flag offensive close merge delete

Comments

Error was corrected as: cv::circle(result, cv::Point2f(center), static_cast<int>(radius), cv::Scalar(0), 2); so cv::Point(center) become this cv::Point2f(center). The problem is likely that I was making a cv::Point from a cv::Point2f. cv::Point is declared as typedef Point2i Point;, meaning that it's equivalent to a cv::Point2i. I was trying to make a cv::Point2i from a cv::Point2f, which is incorrect.

Nenad Bulatovic gravatar imageNenad Bulatovic ( 2013-08-05 14:02:00 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2013-08-05 13:16:04 -0600

berak gravatar image

someone else noted that before

cv::circle(result, center, static_cast<int>(radius), cv::Scalar(0), 2);

might work, imho. (i.e. avoid the constructor call in favour of an assignment

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-08-05 13:01:07 -0600

Seen: 3,068 times

Last updated: Aug 05 '13