在opencv的文件夹中写入图像序列 [英] imwrite sequence of images in a folder in opencv
本文介绍了在opencv的文件夹中写入图像序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C ++中使用VS 2010,并尝试将其置于for循环中
Using VS 2010 in C++ and tried to put this in a for loop
String filename = "cropped_" + (ct+1);
imwrite(filename + ".jpg", img_cropped);
这些是出现的文件名:
ropped_.jpg
opped_.jpg
pped_.jpg
我该怎么做?以及如何将它们放在与源代码相同目录中的文件夹中?
How do I do it? And how do I put them in a folder in the same directory as my source code?
推荐答案
您可以使用std::stringstream
建立顺序文件名:
You can use std::stringstream
to build sequential file names:
首先包含C ++标准库中的sstream
标头.
First include the sstream
header from the C++ standard library.
#include<sstream>
using namespace std;
然后在代码中,您可以执行以下操作:
Then inside your code, you can do the following:
stringstream ss;
string name = "cropped_";
string type = ".jpg";
ss<<name<<(ct + 1)<<type;
string filename = ss.str();
ss.str("");
imwrite(filename, img_cropped);
要创建新文件夹,可以在stdlib.h
中的system
函数中使用Windows的命令mkdir
:
To create new folder, you can use windows' command mkdir
in the system
function from stdlib.h
:
string folderName = "cropped";
string folderCreateCommand = "mkdir " + folderName;
system(folderCreateCommand.c_str());
ss<<folderName<<"/"<<name<<(ct + 1)<<type;
string fullPath = ss.str();
ss.str("");
imwrite(fullPath, img_cropped);
这篇关于在opencv的文件夹中写入图像序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文