1

Given image files

lights000.rgbe
lights001.rgbe
lights002.rgbe
...
lights899.rgbe

Are all located in a single subfolder. What is the best way to read one file then the next?

Given that my read command for .rgbe is called readHDR(char* filename)

I have seen several questions regrading this problem but they all use OpenCV. I am not using opencv and .rgbe is not even a supported OpenCV file extension so that method wouldn't even work.

I saw the following code from a different question:

char* Dataset_Dir( "C:/Data/" ); // Or take it from argv[1]
cv::Mat normal_matrix;
std::vector<cv::Mat>* image_stack;
for( int i=1; i<=endNumber; ++i )
{
    // Gives the entire stack of images for you to go through
    image_stack->push_back(cv::imread(std::format("%s/%03d-capture.png", Dataset, i), CV_LOAD_IMAGE_COLOR)); 

    normal_matrix = cv::imread(std::format("%s/%03d-capture.png", Dataset, i), CV_LOAD_IMAGE_COLOR);
}

But I cannot find any information on the std::format command or the Dataset_Dir.

Any advice for even how to split the file name string into three parts would be really helpful.

Split into:

 char Name = "lights";
 int Num  = "000";
 char File = ".rgbe;
4
  • This is not a duplicate cause this questions - stackoverflow.com/questions/236129/how-to-split-a-string-in-c does not answer mine. It explains how to split a string with spaces Commented Oct 6, 2014 at 21:18
  • 1
    read this answer in that post. You may use any delimiter you would like. Try reading the whole post before jumping to defense. Commented Oct 6, 2014 at 21:19
  • Well, you want to extract the Num value also. There's no delimiter you can use, just you can check if the filename in question starts with "lights", and take the rest up to the '.' as the Num value. Commented Oct 6, 2014 at 21:21
  • But the filename is also not fixed. So what would be the best way to find what that first file is in the folder Commented Oct 6, 2014 at 21:23

1 Answer 1

1

Here's a simple solution, how to split your filename strings by the criteria you specified:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
    istringstream filename("lights042.rgbe");
    string Name;
    int Num;
    string File;

    while(filename && !isdigit(filename.peek())) {
        char c;
        filename >> c;
        Name += c;
    }

    filename >> Num;
    filename >> File;

    cout << "Name = '" << Name << "'" << endl;
    cout << "Num = " << Num << endl;
    cout << "File = '" << File << "'" << endl;

    return 0;
}

Output

Name = 'lights'
Num = 42
File = '.rgbe'

See the live demo please.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.