IplImage Open Image in openCV c++

vidzz picture vidzz · Apr 22, 2013 · Viewed 13.3k times · Source

I have images saved as 1.jpg, 2.jpg and 3.jpg in a folder(at C:/images/result/template/)

I am attempting to load all the images as follow:

string link="C:/images/result/template/";
int i=1;
while (i<4)
{
link=link+i+".jpg";
IplImage* templat  = cvLoadImage(link, 1);
IplImage* templat2 = cvCreateImage(cvSize(templat->width, templat->height), 
IPL_DEPTH_8U, 1);
i++
}

However I am getting error.

error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

Answer

sgarizvi picture sgarizvi · Apr 22, 2013

You can load series of images using sprintf or std::stringstream

Here is how you can do it with sprintf:

char link[512];

int i=1;

while (i<4)
{
  sprintf(link,"C:/images/result/template/%d.jpg",i);
  IplImage* templat  = cvLoadImage(link, 1);
  IplImage* templat2 = cvCreateImage(cvSize(templat->width, templat->height),IPL_DEPTH_8U, 1);
  i++
}