cv::glob(path, filenames)
时间: 2024-04-30 22:22:54 浏览: 11
cv::glob(path, filenames) is a function in the OpenCV library that searches for files in a directory specified by the path argument and stores the names of the found files in a vector of strings called filenames. The function can be used to iterate over all files in a directory that match a specific pattern or file extension. The path argument can contain wildcards, allowing for more flexible file search patterns.
Here's an example usage of cv::glob:
```
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
std::vector<cv::String> filenames;
cv::String path = "path/to/directory/*.jpg"; // search for all .jpg files in directory
cv::glob(path, filenames);
for (const auto& filename : filenames) {
std::cout << filename << std::endl;
}
return 0;
}
```
In this example, cv::glob searches for all .jpg files in the "path/to/directory" directory and stores their names in the vector filenames. The for loop then prints out each filename in the vector.