あるフォルダ内にある画像すべてに2値化処理を行いたいと思い、フォルダ内の画像名の取得まではできたのですがそれをどのようにimread関数に渡せばいいのかわからなくて困っています。
C++
1#include <Windows.h> 2#include <stdexcept> 3#include <iostream> 4#include <vector> 5#include <string> 6#include <opencv2/opencv.hpp> 7#include <opencv2/highgui/highgui.hpp> 8 9using namespace cv; 10using namespace std; 11 12// 入力フォルダ名の指定 13string INPUT_FOLDER_NAME = "フォルダのパス"; 14 15// 指定フォルダ内にある画像名を取得 16vector<string> getImageName(string dir_name) { 17 18 HANDLE hFind; 19 WIN32_FIND_DATA win32fd; 20 std::vector<std::string> file_names; 21 22 // png,jpg,bmpの画像を読み込む 23 std::string extension[3] = { "png" ,"jpg", "bmp" }; 24 25 for (int i = 0; i < 3; i++) { 26 27 string search_name = dir_name + "*." + extension[i]; 28 hFind = FindFirstFile(search_name.c_str(), &win32fd); 29 30 if (hFind == INVALID_HANDLE_VALUE) { 31 continue; 32 } 33 do { 34 if (win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { 35 } 36 else { 37 file_names.push_back(win32fd.cFileName); 38 } 39 } while (FindNextFile(hFind, &win32fd)); 40 41 FindClose(hFind); 42 } 43 return file_names; 44} 45 46int main(void) { 47 48 // ファイル内の画像名の取得 49 vector<string> file_names = getImageName(INPUT_FOLDER_NAME); 50 51 //表示部分 52 for (auto f : file_names) { 53 cout << f << endl; 54 } 55 56//ここで2値化を行おうと思っています。 57 58Mat input_img = imread("ここがわからない", IMREAD_UNCHANGED); 59 60 61 return 0; 62}
ご教授よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/26 02:49
2019/01/26 02:53
2019/01/26 03:02
2019/01/26 07:12
2019/01/26 09:45