Need help with my program

Hello
I am having problem with my code. I am working with VC 6.0 and using opencv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
 // uchar *data;
  int i,j;
  
  float **mat;
  CvScalar s;

  
  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1],0);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
 // data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels %d widthStep\n",height,width,channels,width); 

  mat=malloc(height * sizeof(float*));
  
  for(i=0;i<height;i++)
  {
	  mat[i]=malloc(width * sizeof(float));
  }

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

 

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);
  
  for(i=0;i<height;i++)
  {
	  for(j=0;j<width;j++)
	  {
		  s=cvGet2D(img,i,j); // get the (i,j) pixel value
		  mat[i][j]=s.val[0];
	//printf("intensity=%f\n",s.val[0]);
	  }
  }


  // release the image
  cvReleaseImage(&img );
  return 0;
}


I am getting the following errors

H:\Work\BTP\hello_world\hello_world.cpp(39) : error C2440: '=' : cannot convert from 'void *' to 'float ** '
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
H:\Work\BTP\hello_world\hello_world.cpp(43) : error C2440: '=' : cannot convert from 'void *' to 'float *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
H:\Work\BTP\hello_world\hello_world.cpp(63) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.

hello_world.obj - 2 error(s), 1 warning(s)

Can anyone please help me
Hello!
1
2
3
4
5
6
mat=malloc(height * sizeof(float*));
  
  for(i=0;i<height;i++)
  {
	  mat[i]=malloc(width * sizeof(float));
  }

malloc return a void*. You have to cast it to a (float**) and a (float*)
Try this:
1
2
3
4
5
6
mat=(float**)malloc(height * sizeof(float*));
  
  for(i=0;i<height;i++)
  {
	  mat[i]=(float*)malloc(width * sizeof(float));
  }


It worked..... thnx a lot
Topic archived. No new replies allowed.