C++ 使用不同的文件名读入图像集,无需硬编码
c++ read in image set with different file names without hardcoding
有没有办法从文件中读取一组图像,这些图像彼此具有不同的名称,即根本没有连续性?
因此,如果您在同一文件夹中有 4 张文件名为:
- 头.jpg
- 肩膀.png
- 膝盖.tiff
- 脚趾.bmp
无需直接对文件名进行硬编码,因此您可以更改肩膀.png比如手臂.gif,有没有办法将它们加载进来?
我目前有OpenCV和Boost可用
对于其他任何想知道的人:
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
std::vector<cv::Mat> imageVec;
fs::path p (".");
fs::directory_iterator end_itr;
// cycle through the directory
for (fs::directory_iterator itr(p); itr != end_itr; ++itr){
// If it's not a directory, list it. If you want to list directories too, just remove this check.
if (fs::is_regular_file(itr->path())) {
if (fs::is_regular_file(itr->path())){
cv::Mat img;
img = cv::imread(itr->path().string());
if(img.data) imagesVecc.push_back(img);
}
// assign current file name to current_file and echo it out to the console.
std::string current_file = itr->path().string();
std::cout << current_file << std::endl;
}
}
相关文章:
- Base64 图像编码不正确
- 当通过tcp接收编码图像的消息时,zmq在第二个循环中崩溃
- 如何将 MATLAB 图像处理库内置函数转换为 MATLAB 编码器代码生成不支持的 C++?
- 如何将硬编码图像加载到 OpenGL 纹理中
- 将原始视频图像转换为VPX编码器的I420
- 将 JPG 编码数组从 ROS sensor_msgs/压缩图像保存到 roscpp 中的文件
- BASE64图像文件用C 编码
- FFMPEG H264对每个图像进行编码
- OpenCV 如何为imencode编码原始图像信息
- 如何使用Imebra库将压缩像素(用我自己的编码器压缩)回到DICOM图像文件中
- 在FLTK中显示Base64编码图像
- 同一图像的不同 base64 编码
- JPEG编码位图(BMP)图像从文件使用libjpeg / C++
- Windows媒体基础使用原始图像对视频进行编码
- 用Qt解码用Java ImageIO类编码的图像
- C++图像编码/解码库
- 如何根据C++程序中生成的多个图像对视频进行编码,而不将单独的帧图像写入磁盘
- 用c++将数组编码为jpeg图像
- GTKmm:对文件中的图像进行编码
- WebM编码器示例-如何将一系列图像编码为WebM视频