Lỗi expression must have pointer-to-object type năm 2024

If I declare the variable Iconv in the main() function as an array, that is float Iconv[11][11];, the warning (that

variable "Iconv" was set but never used) disappear, but I am getting another two errors as a result:"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

  • 09-30-2013
    Registered User ---
    An array is not magically converted to a single value, or vice versa. That explains the errors. imageConvolved is specifed as a 2D array (in the function arguments). The function returns a single float value. Hence the complaint about return value type not matching function type (and the error you get when you change IConv to be an array - the compiler believes you are trying to store a single float value as an array).

The warning is simply means you assign the return value from the function to a variable, but then never subsequently use that variable. Right 98% of the time, and don't care about the other 3%.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

-
  • 09-30-2013

    and the hat of int overfl

    - So if you make the function return void, remove the return statement and the return result assignments in main, does it work?

The whole image result will be in your 11x11 result array.

-
  • 09-30-2013

    Registered User

    - Thanks for the comments. Very useful...! It is now working (in the GCC compiler under UBUNTU environment), and below is a complete code:

Code:

//

include"standard_library.h"

//

include"SuperResolution.h"

include<stdio.h>

include<math.h>

void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11]);//Function Prototype definition void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][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; //float imageConvolved[11][11]; 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;

} } res[i-kernelSize/2][j-kernelSize/2] = sum; } } //res=imageConvolved; //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 res[11][11]; //float Iconv[11][11]; int i,j,m,n; for(i=0;i<11;i++) for(j=0;j<11;j++) res[i][j]=0.0; conv2D(rowsK, colsK, rowsI, colsI, gauss, img,res); for(m=0;m<11;m++) for(n=0;n<11;n++) { printf("%4.0f",res[m][n]); if(n==10) printf("\n"); } return 0; }

The result when compiled and run is: This code explains the convolution of an image with a kernel. The indicated matrices, however, can be replaced by real matrices (The convolution kernel and image).

In the CCStudio V3.3, however, I am still getting some errors when I compile, and I am still struggling on getting a way forward. Here are the errors in the CCStudio: ---- super_resolution.pjt - Debug ----

[convolution.c] "C:\CCStudio_v3.3\C6000\cgtools\bin\cl6x" -g -pdsw225 -fr"C:/Documents and Settings/Administrator/Desktop/testPrograms/super_resolution/Debug" -d"_DEBUG" -mv6400 -@"Debug.lkf" "convolution.c"

Warning: The project has no cmd file while the Text Linker is selected [Linking...] "C:\CCStudio_v3.3\C6000\cgtools\bin\cl6x" -@"Debug.lkf" <Linking> \>> warning: entry point symbol _c_int00 undefined

undefined first referenced symbol in file - ----

__mpyf C:\\Documents and Settings\\Administrator\\Desktop\\testPrograms\\su per_resolution\\Debug\\convolution.obj __addf C:\\Documents and Settings\\Administrator\\Desktop\\testPrograms\\su per_resolution\\Debug\\convolution.obj __strasgi C:\\Documents and Settings\\Administrator\\Desktop\\testPrograms\\su per_resolution\\Debug\\convolution.obj __fltif C:\\Documents and Settings\\Administrator\\Desktop\\testPrograms\\su per_resolution\\Debug\\convolution.obj \>> error: symbol referencing errors - './Debug/super_resolution.out' not built

\>> Compilation failure

Build Complete, 2 Errors, 2 Warnings, 0 Remarks.

I am thinking that I the problem may be caused by the settings of my compiler, or something is wrong with the linking of the files during the compilation process.

09-30-2013

and the hat of int overfl

-

\> In the CCStudio V3.3, however, I am still getting some errors when I compile, and I am still struggling on getting a way forward. Here are the errors in the CCStudio: Those are link errors, not compile errors.

Since your code uses just standard C, the easy thing would be to just create a new console project and copy/paste your code into it.

-
  • 10-02-2013

    Registered User

    Great...!! Now it works, and it can also be used for anyone who would like to convolve 2D matrices. A slight modification can be done if one needs to convolve an image with a Gaussian Kernel, since the given matrices a constant (used for testing purposes). My next movie is to perform the convolution using real data. Here are the source codes: main.c Code:

include"standard_library.h"

include"SuperResolution.h"

int main() { int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15; float res[11][11]; int i,j,m,n; for(i=0;i<11;i++) for(j=0;j<11;j++) res[i][j]=0.0; conv2D(rowsK, colsK, rowsI, colsI, gauss, img,res); for(m=0;m<11;m++) for(n=0;n<11;n++) { printf("%4.0f",res[m][n]); if(n==10) printf("\n"); } return 0; } conv.c Code: void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][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; //float imageConvolved[11][11]; 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; } } res[i-kernelSize/2][j-kernelSize/2] = sum; } } } SuperResolution.h Code:

ifndef _SUPERRESOLUTION_H

define _SUPERRESOLUTION_H

void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11]);//Function Prototype definition float gauss[][5]={ {1, 2, 4, 2, 1}, {2, 1, 1, 1, 2}, {4, 8, 8, 8, 4}, {2, 1, 1, 1, 2}, {1, 2, 4, 2, 1} }; int img[][15]={ {1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} };

endif

standard_library.h Code:

ifndef _STANDARD_LIBRARY_H

define _STANDARD_LIBRARY_H

//Include standard header files

include<math.h>

include<stdio.h>

endif

RESULT Note that the result of convolution is not the same size as the original convoluting matrix because of cropping at the boundaries. This is one way of implementing convolution, although there are other ways which keep the two matrices (convoluting matrix and result) the same in dimension.

Chủ đề