1

When I try to compile this piece of code I am getting this error-

error: no matching function for call to 'glob(std::__cxx11::string&, std::vector >&, bool)' glob (folder, filename, false); ^

This is the code I used:

    #include <vector>
    #include <glob.h>

    string folder = "/home/ragesh/C++ /calibration_laptop/images/*.jpg";
    vector <string> filename;
    glob(folder, filename, false);
    if(count < filename.size())
    {

        img = imread(filename[count]);
        if(img.empty())
        {
            cout << "\nimage loading failed.....!"<<"\n";
            return 0;
        }
        imshow("image", img);
        cvtColor ( img,gray, COLOR_BGR2GRAY );// gray scale the source image
        vector<Point2f> corners; //this will be filled by the detected corners

        bool patternfound = findChessboardCorners(gray, boardSize, corners, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CALIB_CB_FAST_CHECK);
        count ++;
    }
Scipione Sarlo
  • 1,470
  • 1
  • 17
  • 31
Ragesh_
  • 93
  • 1
  • 7
  • 1
  • @MarkSetchell Even when I added ( folder.c_str() )'code' I am getting the same error. – Ragesh_ May 07 '18 at 09:48
  • 1
    Looking at the signature of `glob`, I'd say the problem is with the second parameter. You can construct a `cv::String` from a `std::string`, but that won't help with a non-const reference to a vector... – Dan Mašek May 07 '18 at 12:55
  • 1
    As usual, an actual [MCVE] wouldn't hurt -- missing includes, missing namespace qualifiers, no `main()`, code outside a function... what's that supposed to be? – Dan Mašek May 07 '18 at 13:10

2 Answers2

4

The function cv::glob has the following signature:

void cv::glob(cv::String pattern, std::vector<cv::String>& result, bool recursive = false)  

Since pattern is passed by value, and a cv::String can be constructed from a std::string, the first parameter is not a problem. A temporary cv::String is automatically constructed.

However, the second one -- result -- is, since it's taken as a non-const reference. In order to fix your problem, you need to make filename a std::vector<cv::String>. Since it represents a collection of file names, I'd also suggest using plural to name it: filenames.

Example code:

#include <opencv2/opencv.hpp>

#include <string>
#include <vector>

int main()
{
    std::string folder("/home/ragesh/C++ /calibration_laptop/images/*.jpg");
    std::vector<cv::String> filenames;
    cv::glob(folder, filenames, false);

    // Do something with filenames...

    return 0;
}

Update:

I concluded from the signature, and the tags on your question, that you're after the OpenCV glob (the incomplete code sample makes that somewhat difficult). However, note that the header you included is for the Posix glob function.

There's a good chance that was another cause of problems.

For completeness, let me list the rest of the issues I find with your code sample:

  • Missing includes (opencv, string)
  • Missing namespace qualifiers (std:: or cv:: -- avoid using namespace at top level)
  • No main()
  • Code outside a function
  • A bunch of other unrelated code after the relevant bit, which I won't analyze further (but roughly 80% of your code sample is irrelevant).
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
2

Try to use CV::String instead of std::string.

Add #include "cvstd.hpp", then

cv::String new_folder_string(folder).
std::vector<cv::String> new_filename_vector.
glob(new_folder_string, new_filename_vector, false);

Some info here(glob function), here(String class in OpenCV), here(example of use of glob with cv::String) and here(berak's suggestion).

EDIT: I forgot to mention that you need to switch also filename from std::string to cv::String.

lezan
  • 759
  • 6
  • 23