Pointer to image producing different results

asked 2016-09-29 05:00:38 -0600

_chris gravatar image

updated 2016-09-29 05:02:08 -0600

I'm doing the following:

  image = image.clone(); // ensure continuous memory
  double *im = (double *) calloc(image.total() *image.elemSize(), sizeof (double));
  im = (double *)image.data;

What I thought this was doing was giving me a pointer to the image data, however when i print out the memory in a debugger I get different values after I add the same offset to both (i.e. x/100 image.data+100 != x/100 im+100).

Is my pointing not doing what I think it is and if so why?

The reason I'm doing this is because I'm trying to port some mex stuff, and the whole function relies on a pointer to an rgb image and address offsetting.

edit retag flag offensive close merge delete

Comments

2

wtf, there's almost nothing right with your current approach.

  • you're assuming, the Mat's type is double. that'll be rarely be the case, if it's an image.
  • image.total() *image.elemSize() is the size in bytes, but again, you're allocating doubles.
  • im = (double *)image.data; <-- this just overwrites your pointer, it does not copy memory (also, you're leaking your just allocated mem)

honestly, it might be a good idea, to leave the mex stuff to someone else.

berak gravatar imageberak ( 2016-09-29 06:09:09 -0600 )edit