Imread a string location

asked 2014-07-27 10:01:17 -0500

Tduck gravatar image

updated 2014-07-27 10:04:51 -0500

I'm trying to load images from locations written in a file. It reads the string fileLocation correctly, and if I write the actual location (for example: imread("images/tif/image-001.tif", 1)) it also works. However, combining them seems to give me an empty image message. Please help.

// Read the file location from the file called locations.txt and save it to a string called fileLocation
string fileLocation;
ifstream infile; ("locations.txt");
getline(infile, fileLocation);

// Read image with location fileLocation
imageColor = imread(fileLocation, 1);

// Check to see if the image has read properly
if (imageColor.empty())
    cout << "Image is empty\n";
    return -1;
edit retag flag offensive close merge delete


isn't it should be infile in the imageColor argument ?

FLY gravatar imageFLY ( 2014-07-27 11:44:38 -0500 )edit

Ok, this is weird but try at first to apply a cout of fileLocation right after the getline function. Are you sure the outputted data is identical to the hard coded path?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-28 02:56:41 -0500 )edit