c - IplImage 的动态数组 - 与 ‘operator=’ 错误不匹配

标签 c opencv dynamic-allocation iplimage

我正在使用 IplImage 类型的动态数组来存储一些图像(我想对 cvHistogram 做同样的事情,但得到相同的错误),我需要从中提取直方图数据。不幸的是我收到了错误并且不知道如何解决它。任何以其他方式执行此操作的帮助和建议将不胜感激。

这是代码的一部分:

void getColorHistogram( void ){

    IplImage *images = (IplImage *)malloc( sizeof(IplImage) * 6 );

    if ( images == NULL )
    {
        printf("Memory error. EXITING...\n");
        exit( -1 );
    }

    for (int i = 0; i < 6 ; i++ ){

        char *num = (char *)malloc( sizeof(int) );
        char *extension = (char *)".jpg";
        sprintf( num, "%d", i );

        int nameLen = strlen( num ) + strlen( extension ) + 1;

        char *imgName = (char *)malloc( nameLen );
        strlcpy( imgName, num, nameLen );
        strlcat( imgName, extension, nameLen );

        images[i] = cvLoadImage( imgName, CV_LOAD_IMAGE_UNCHANGED );
    }

    free( images );

}

这是我得到的错误

    error: no match for ‘operator=’ in ‘images[i] = cvLoadImage
(((const char*)imgName), -0x00000000000000001)’
    /opt/local/include/opencv2/core/types_c.h:463: note: 
candidates are: _IplImage& _IplImage::operator=(const _IplImage&)

附注我正在使用i<6循环中因为 sizeof(images)/sizeof(images[0])给我 0。

非常感谢!

最佳答案

我假设这是一个 C++ 编译。函数调用返回一个 const 指针,并且您的数组不是 const 指针列表。

关于c - IplImage 的动态数组 - 与 ‘operator=’ 错误不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17458068/

相关文章:

c++ - 实现对象列表时如何处理动态分配?

c++ - malloc 的优点是什么?

c - 如何将函数的指针返回给指针,C语言

c - 新指针(通过 malloc)与释放/旧指针之一相同

c - 在 C 中打开和读取文件

python - 如何用opencv填充盒子里面的盒子

python - opencv:在 mac 上的 python import cv2 期间出现段错误

c - 从变量中读取值

python - 让 haar 级联工作

c++ EOF 运行次数过多?