读取一个文件夹中的所有图片,对图像进行操作之后,将操作后的图片存储到一个文件夹中;
_findfirst返回的参数是intptr_t类型的,定义成long类型的,程序会报错。
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cout << "Usage: images file path error" << std::endl;
}
struct _finddata_t file;
intptr_t If;
std::string path,tempPath; //遍历文件夹中的所有图片
path = path.assign(argv[1]); //文件的路径
tempPath = path.assign(argv[1]);
if ((If = _findfirst(path.append("\\*").c_str(), &file)) == -1) //不加*也会报错
{
std::cout << "Not find image file" << std::endl;
}
else
{
while (_findnext(If, &file) == 0)
{
std::cout << "file name: " << path.substr(0, path.length() - 1) << file.name << std::endl;
cv::Mat srcImage = cv::imread(tempPath + "\\" + file.name, 0);//第一个图片路径..是打不开的

本文介绍如何使用C++批量读取一个文件夹中的所有照片,进行图像处理,然后将处理后的图片保存到指定位置。在实现过程中需要注意_long类型与intptr_t类型之间的转换问题,避免程序报错。
最低0.47元/天 解锁文章
3658

被折叠的 条评论
为什么被折叠?



