0
ディレクトリを繰り返し処理し、n番目のファイルをスキップすることを許可している間に画像を読み取ろうとしています。範囲外に移動する前にディレクトリ_iteratorを停止する
私のコードは、現在、次のようになります。skipSlices = 1
場合
// Count number of files in directory and reserve memory (take skipped slices into account)
std::experimental::filesystem::directory_iterator it_begin{path};
int count = count_if(it_begin, std::experimental::filesystem::directory_iterator(), [](const std::experimental::filesystem::directory_entry & d) {return !is_directory(d.path());});
auto maxCount = count - (count % (1 + skipSlices));
m_imageStack.reserve(maxCount);
// Read image stack and check for validity
int n = 0;
for (std::experimental::filesystem::v1::directory_iterator it(path); it != std::experimental::filesystem::v1::directory_iterator(); std::advance(it, 1 + skipSlices))
{
std::string filename{std::experimental::filesystem::v1::path(*it).string()};
cv::Mat image = cv::imread(filename);
m_imageStack.push_back(image);
n = n + 1 + skipSlices;
if (n == maxCount) break;
}
、私はすべての第二画像を読みたい、など境界の外に移動していないために、私は、forループ内のブレーク条件を追加しました。今私の解決策は本当に悪いです。私は休憩を取り除き、for-loopでより正確な停止条件を使用したいと思います。しかし、あまりにも多くを進める前に、イテレータが停止するように指示する方法は見つけられませんでした。どのようにこれを解決することができる任意のアイデア?