C++ IplImage openCV c++;

C++ IplImage openCV c++;,c++,opencv,loadimage,C++,Opencv,Loadimage,我在一个文件夹中将图像保存为1.jpg、2.jpg和3.jpg(位于C:/images/result/template/) 我正在尝试加载所有图像,如下所示: string link="C:/images/result/template/"; int i=1; while (i<4) { link=link+i+".jpg"; IplImage* templat = cvLoadImage(link, 1); IplImage* templat2 = cvCreateImage(cvSi

我在一个文件夹中将图像保存为1.jpg、2.jpg和3.jpg(位于C:/images/result/template/)

我正在尝试加载所有图像,如下所示:

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++
}
string link=“C:/images/result/template/”;
int i=1;
而(iwidth,templat->height),
IPL_深度_8U,1);
我++
}
然而,我得到了错误

错误C2678:二进制“+”:未找到接受类型为“std::string”的左侧操作数的运算符(或没有可接受的转换)

link=link+i+“.jpg”

没有做你认为它做的事-事实上,我很惊讶它能编译

另外,您需要检查cvLoadImage()返回的内容,以检查它是否实际加载了任何内容。
pps。您应该使用cv::imread()

link=link+i+“.jpg”

没有做你认为它做的事-事实上,我很惊讶它能编译

另外,您需要检查cvLoadImage()返回的内容,以检查它是否实际加载了任何内容。

pps。您应该使用cv::imread()

您可以使用
sprintf
std::stringstream

下面是使用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++
}
char链接[512];
int i=1;
而(iwidth,templat->height),IPL_DEPTH_8U,1);
我++
}

您可以使用
sprintf
std::stringstream

下面是使用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++
}
char链接[512];
int i=1;
而(iwidth,templat->height),IPL_DEPTH_8U,1);
我++
}

检查路径,因为路径不正确时:
link=null
检查路径,因为路径不正确时:
link=null
尝试此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
}
string link=“C://images//result//template//”//请将“/”改为“/”
int i=1;
而(iwidth,templat->height),IPL_DEPTH_8U,1);
i++//放分号
}
试试这个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
}
string link=“C://images//result//template//”//请将“/”改为“/”
int i=1;
而(iwidth,templat->height),IPL_DEPTH_8U,1);
i++//放分号
}