C 错误:返回值类型与函数类型不匹配
下面是一个代码:C 错误:返回值类型与函数类型不匹配,c,arrays,pointers,gcc,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 row
#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;
}
#包括
#包括
float-conv2D(int-rowsKernel、int-colsKernel、int-rowsImage、int-colsImage、float-kernel[][5]、int-image[][15]、float-imageConvolved[][11])//功能原型定义
浮点conv2D(int-rowsKernel、int-colsKernel、int-rowsImage、int-colsImage、浮点内核[][5]、int-image[][15]、浮点图像卷积[][11])
{
int kernelSize;//此变量表示高斯核的大小
int i;//控制图像行的变量
int j;//控制图像列的变量
int ii;//控制内核行的变量
int jj;//控制内核列的变量
float sum;//保存图像特定像素卷积结果的变量
//浮点图像卷积;//由高斯核卷积的图像的结果
整数像素;
浮动核像素;
KelnSeals= CLSKENEL;/*,因为我们考虑平方核,然后RoSkeNeNe= CLSKENEL,这意味着内核的大小(KelnSead)等于这两个变量中的任一个(即,Kalnsiths= CLSKeNeNe= RoSkeNeL)*/
for(i=kernelSize/2;i 对于(ii=-kernelSize/2;ii您正在从一个函数返回一个二维数组(imageConvolved
),该函数根据其声明返回float
。我不知道您想从该函数返回什么,但似乎错误在这一行:
return(imageConvolved);
函数conv2D
的原型是float。但是,在您返回的imageConvolved
定义中,imageConvolved
是ormal参数
中的一个数组,您不需要返回它,因此您需要返回float
类型insead的内容。请粘贴真实代码,包括每个参数及其类型,作为代码;不隐藏在段落中。您的描述,“其中此函数中的参数声明为浮点结果、int-rowsK、int-colsK、int-rowsI和int-colsI”很方便地遗漏了最后两种参数类型,如果不明显,它们对发现问题至关重要。因此,讽刺的是,它们没有包括在内。简而言之,不要只告诉我们“关于”你的代码;显示它。什么是imageConvolved
?你可以作为2D数组访问它,然后以float
返回它。你想要哪一个?我同意上面的评论。你的问题很难回答。将代码作为代码块,而不是作为粗体块包含在段落中。你说imageConvolved定义为float,但是你的行为就像它是一个2D数组。你从返回float的函数中返回它,因此它似乎是一个裸浮点值,你尝试将其用作2D数组。如果你只是复制并粘贴你的代码可能会更好。你是说imageConvolved
是这样声明的:float imageConvolved
?在这种情况下清楚为什么编译器不喜欢它,因为你像访问2d数组一样访问它。@ChrisWue似乎imageConvolved是一个输入参数,是二维浮点数组。问题已经解决了(当我使用GCC编译器编译时)。它使函数conv2D在调用点和main()中不返回任何内容函数我正在将另一个收集结果的参数传递给函数conv2D。然后我可以轻松地从main()函数读取结果。