Using opencv and c++ I am attempting to write a program that given a file path, the program will duplicate every image in that file. This is what I have written using imread and imwrite:
#include <filesystem> #include <fstream> using namespace std; using namespace cv; namespace fs = std::filesystem; Mat duplicateImage(string filename) { // Load the input image Mat image = imread(filename, IMREAD_UNCHANGED); // Create a duplicate image Mat duplicate = image.clone(); return duplicate; } int main(int argc, char** argv) { string directory_name = "C:\\My\\File\\Path\\Name"; vector<string> files_list; ifstream file_stream(directory_name); string line; while (getline(file_stream, line)) { files_list.push_back(line); } // Duplicate each image in the directory for (string filename : files_list) { Mat duplicate = duplicateImage(filename); string output_filename = filename + "_copy"; // new filename for the duplicate; cv::imwrite(output_filename, duplicate); } } When I open up the file path there are no changes made to the file.
I had initially attempted to fo this with fstream which resulted in the same issue, the file not being modified at all. any advice would be greatly appriciated!
EDIT: I have discovered a bug - I am not even entering the for loop, I know this because I did a print statement and am not seeing it in the concile. I'm am unsure why I would not be entering the for loop.
inputImage.jpg_copy?