将IplImage **转换为IplImage *时出错

时间:2011-11-21 17:36:52

标签: image opencv iplimage

IplImage *img;
img = (IplImage **)malloc(IMAGE_NUM * sizeof(IplImage *));

for(index=0; index<IMAGE_NUM; index++){
    sprintf(filename, "preproc/preproc%d.jpg", index);
    img = cvLoadImage(filename, 0);
}

嗨!这段代码产生错误:无法在赋值时将'IplImage ** {aka _IplImage * }'转换为'IplImage {aka _IplImage *}'。我想在这里加载多个图像。我究竟做错了什么?谢谢!

3 个答案:

答案 0 :(得分:0)

您声明'img'是指向IplImage的指针,然后您尝试将其转换为指向指针的指针。 (IplImage**) - 由于您尝试将IplImage **分配给IplImage *,因此针对此特定情况的类型转换不正确。

将img声明为:IplImage ** img;

答案 1 :(得分:0)

试试这个

IplImage** img;
img = (IplImage**)malloc(IMAGE_NUM * sizeof(IplImage *));

for(index=0; index<IMAGE_NUM; index++){
    sprintf(filename, "preproc/preproc%d.jpg", index);
    *img = cvLoadImage(filename, 0);
}

顺便说一下,你将得到的下一个错误是在每次循环迭代后没有推进img指针

答案 2 :(得分:0)

尝试声明IplImage** img;,然后声明img[index] = cvLoadImage(filename, 0),因为img是一个IplImage指针数组,cvLoadImage()返回单个图像。

相关问题