c++,检查某个索引是否在一个set容器内,如果存在,就用opencv的方法存储这个索引所对应的照片到本地
时间: 2024-03-03 13:47:39 浏览: 7
以下是示例代码:
```c++
#include <opencv2/opencv.hpp>
#include <set>
int main() {
std::set<int> index_set = {1, 2, 3, 4}; // 假设 set 容器内已经存在索引 1,2,3,4
const std::string image_folder = "path/to/image/folder/"; // 存储图片的文件夹路径
// 遍历需要检查的索引
for (int index = 1; index <= 4; ++index) {
// 如果索引存在于 set 容器内
if (index_set.count(index) > 0) {
// 读取图片
const std::string image_path = image_folder + std::to_string(index) + ".jpg";
cv::Mat image = cv::imread(image_path);
// 存储图片到本地
const std::string save_path = "path/to/save/folder/" + std::to_string(index) + ".jpg";
cv::imwrite(save_path, image);
}
}
return 0;
}
```
注意,需要安装 OpenCV 库并正确添加头文件路径和链接库。此外,代码中的路径需要根据实际情况进行修改。