c - 错误: return value type does not match the function type

标签 c arrays pointers gcc

这是一个代码:

#include<stdio.h>
#include<math.h>

float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float imageConvolved[][11]); //Function Prototype definition

float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float imageConvolved[][11])
{
    int kernelSize;     //This variable represents the size of the Gaussian kernel
    int i;          //variable which controls the rows of an image
    int j;          //variable which controls the columns of an image
    int ii;         //variable which controls the rows of the kernel
    int jj;         //variable which controls the columns of the kernel
    float sum;          //variable that holds the result of convolution for a particular pixel of an image
//float imageConvolved;//Result of an image convolved by a Gaussian kernel
    int imagePixel;
    float kernelPixel;
    kernelSize = colsKernel;    /*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the                 kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel) */
    for (i = kernelSize / 2; i < rowsImage - kernelSize / 2; i++)   // perform iteration through the rows of an image
    {
    for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++)   // perform iteration through the columns of an image
    {
        sum = 0;        /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel */
        for (ii = -kernelSize / 2; ii <= kernelSize / 2; ii++)  // perform iteration through the rows of a kernel
        {
        for (jj = -kernelSize / 2; jj <= kernelSize / 2; jj++)  //perform iteration through the columns of a kernel
        {
            imagePixel = image[i + ii][j + jj];
            kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];

            sum += imagePixel * kernelPixel;
        }
        }
        imageConvolved[i - kernelSize / 2][j - kernelSize / 2] = sum;
    }
    }
    return (imageConvolved);    // convolved image
}

int main()
{
    float gauss[][5] = {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
    };
    int img[][15] = {
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
    };
    int rowsK = 5, colsK = 5, rowsI = 15, colsI = 15;
    float result[11][11];
    float Iconv[11][11];
    Iconv = conv2D(rowsK, colsK, rowsI, colsI, gauss, img, result);
    return 0;
}

我修改了代码以尝试解决问题。但是,我收到两个错误(使用 CCStudio V3.3):

"convolution.c", line 39: error: return value type does not match the function type "convolution.c", line 71: error: expression must be a modifiable lvalue

最佳答案

您正在从一个根据其声明返回 float 的函数返回一个看似二维数组 (imageConvolved) 的内容。我不知道你从函数返回是什么意思,但似乎错误就在这一行:

return(imageConvolved);

关于c - 错误: return value type does not match the function type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085674/

相关文章:

C - 简单模数表有问题,它不是那么简单

c - memcpy(),size参数的值应该是多少?

用 sizeof 初始化常量数组

c - 指针变量存储什么?

C 编程指针——为什么我的值会改变?

c - GDB 跳过行为

c - strtok在c中返回int类型

c - stdout 流在重定向后更改顺序?

javascript - 将单词和定义列表拆分为两个数组

pointers - 在 Go 的循环中处理指针结构的正确方法是什么?