Вопрос

I have the following compiler error : "call of overloaded ‘reduceColors(ipl_image_wrapper&, ipl_image_wrapper&, int)’ is ambiguous"

I have a wrapper class for IplImage (DrawingDetection.h):

#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <boost/shared_ptr.hpp>

#include "Utils.h"

class ipl_image_wrapper
{
public:
    typedef boost::shared_ptr< IplImage > ipl_image_ptr_t;

    ipl_image_wrapper() {}
    ipl_image_wrapper( IplImage* img ) : _img( img, ipl_deleter ) {}

    IplImage*       get()       { return _img.get(); }
    const IplImage* get() const { return _img.get(); }

private:

static void ipl_deleter( IplImage* ipl_img )
{
 //some code
}

   ipl_image_ptr_t _img;
};

And I have the following functions (Utils.h):

#include "DrawingDetection.h"

int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor);
void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper &out, int levels);
int calculateCComponentsSize(const ipl_image_wrapper &img, Factor &factor);

There is no other declarations of this functions (!). I'm not overloading them.

And source code with error (Utils.cpp):

#include <boost/shared_ptr.hpp>
#include "Utils.h"


int calculateCComponentsSize(const ipl_image_wrapper img, Factor &factor)
{
    // some calculations
}
 void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper out, int levels)
{
    // some calculations
}
int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor)
{
    // some calculations
}
void getFactorsOfImage( const ipl_image_wrapper &image, Factor& factor )
{
    ipl_image_wrapper gray = cvCreateImage( cvGetSize ( image.get() ), IPL_DEPTH_8U, 1);

    // some calculations
    calculateHomogeneity( gray, factor ); // ok
    reduceColors( gray, gray, 20 ); // ambiguity !!
    int n1 = calculateCComponentsSize( gray, factor );// ambiguity !!
    reduceColors( gray, gray, 8 );// ambiguity !!
    int n2 = calculateCComponentsSize( gray, factor );// ambiguity !!

    // some calculations
}

What is the diiference between calculateHomogeneity(...) function and the rest? They have a similar list of parameters. Where the compiler found the ambiguity?

EDIT:

Declaration order of function has been very important.

Source code without error (Utils.cpp):

#include <boost/shared_ptr.hpp>
#include "Utils.h"

void getFactorsOfImage( const ipl_image_wrapper &image, Factor& factor )
{
    ipl_image_wrapper gray = cvCreateImage( cvGetSize ( image.get() ), IPL_DEPTH_8U, 1);

    // some calculations
    calculateHomogeneity( gray, factor ); // ok
    reduceColors( gray, gray, 20 ); // ambiguity !!
    int n1 = calculateCComponentsSize( gray, factor );// ambiguity !!
    reduceColors( gray, gray, 8 );// ambiguity !!
    int n2 = calculateCComponentsSize( gray, factor );// ambiguity !!

    // some calculations
}
// After getFactorsOfImage function
int calculateCComponentsSize(const ipl_image_wrapper img, Factor &factor)
{
    // some calculations
}
 void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper out, int levels)
{
    // some calculations
}
int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor)
{
    // some calculations
}
Это было полезно?

Решение

There actually are two different reduceColors functions: the one that's declared, whose second argument is ipl_image_wrapper&, and the one that's defined, whose second argument is ipl_image_wrapper. Make them the same.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top