Ambiguous call of overload in segmented_word_recognition.cpp

I am trying to build opencv2 in my Ubuntu 18.04 laptop when an error popped up while running the make command in build.


opencv_contrib/modules/text/samples/segmented_word_recognition.cpp:94:85: error: call of overloaded ‘create(cv::Ptr<cv::text::OCRHMMDecoder::ClassifierCallback>, std::__cxx11::string&, cv::Mat&, cv::Mat&)’ is ambiguous
                                  voc, transitionProbabilities, emissionProbabilities);

I have checked the segmented_word_recognition.cpp file in latest git updates its all same. Can anyone please help with the solution. TIA

to clarify: building the libs went all fine, but now, when building that sample, error occurs ?

Yes, cmake went all fine without any errors, it is when I ran the make command for compiling.

1 Like

actually, i think, your compiler is correct about it , and there’s a flaw in the sample code / library design.

look here , since both mode & classifier args have default values – the only non ambiguous way means specifying both of them, so we catch the 2nd overload (at least !)

can you try to modify the sample code (L92-98) like:

Ptr<OCRHMMDecoder> ocrNM  = OCRHMMDecoder::create(
                             loadOCRHMMClassifierNM("./OCRHMM_knn_model_data.xml.gz"),
                             voc, transitionProbabilities, emissionProbabilities,OCR_DECODER_VITERBI,  OCR_KNN_CLASSIFIER);

Ptr<OCRHMMDecoder> ocrCNN = OCRHMMDecoder::create(
                             loadOCRHMMClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz"),
                             voc, transitionProbabilities, emissionProbabilities, OCR_DECODER_VITERBI, OCR_KNN_CLASSIFIER);

Thanks a lot for the suggestion & time, but still L92-98 giving error:

error: no matching function for call to ‘cv::text::OCRHMMDecoder::create(cv::Ptrcv::text::OCRHMMDecoder::ClassifierCallback, std::__cxx11::string&, cv::Mat&, cv::Mat&, cv::text::decoder_mode, cv::text::classifier_type)’
voc, transitionProbabilities, emissionProbabilities, OCR_DECODER_VITERBI, OCR_KNN_CLASSIFIER);

ok, sorry, could not check myself ;(

also, strike the idea, i’m wrong.

1 Like

Thanks @berak for the time and effort I have just resolved the issue, in OCR.hpp the OCR classifier has been defined as

OCR_KNN_CLASSIFIER = 0
OCR_CNN_CLASSIFIER = 1

and hence I changed the L92-98 like this:

Ptr<OCRHMMDecoder> ocrNM  = OCRHMMDecoder::create(
                             loadOCRHMMClassifierNM("./OCRHMM_knn_model_data.xml.gz"),
                             voc, transitionProbabilities, emissionProbabilities, 0);

Ptr<OCRHMMDecoder> ocrCNN = OCRHMMDecoder::create(
                             loadOCRHMMClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz"),
                             voc, transitionProbabilities, emissionProbabilities, 1);

and it started compiling again.
Thanks a lot for the time.

1 Like