문제

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)

도움이 되었습니까?

해결책

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++
}

다른 팁

link=link+i+".jpg";

Doesn't do what you think it does - in fact I'm amazed it compiles.

ps. you need to check the return from cvLoadImage() to check if it actually loaded anything.
pps. you should use cv::imread()

check the path, because when the path is not correct: link = null

try this plz..

string link="C://images//result//template//";  //Please put '//' instead of '/'
int i=1;
while (i<4)
{
link=link+i+".jpg";
IplImage* templat  = cvLoadImage(link.c_str(), 1); // instead of string, use char*
IplImage* templat2 = cvCreateImage(cvSize(templat->width, templat->height),IPL_DEPTH_8U,1);
i++; //put semi-colon
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top