Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read multiple images from a path in c++?

I have to extract HOG features of 37 images from a folder(RGB images), hence i wrote the following code. But when i run this ,the program breaks in 'if (!img.data)' .

using namespace cv; using namespace std;

int main()

{

HOGDescriptor hog;

hog.winSize = Size(32, 48);

for (size_t i = 1; i <= 37; ++i)
{

    ostringstream os;
    os << " C:/Users/Sam/Desktop/HumanCount/Training Images/Content/ " << "positive\\" << std::setw(4) << std::setfill('0') << i << ".JPG";

    Mat img = imread(os.str(), CV_LOAD_IMAGE_GRAYSCALE);

    if (!img.data)
    {
        break;
    }
    else
    {

        // obtain feature vector:
        vector<float> featureVector;
        hog.compute(img, featureVector, Size(8, 8), Size(0, 0));

    }


    return 0;
}

}