How to convert unsigned int to unsigned char* in C++ ?

asked 2015-05-30 06:37:34 -0600

sidPhoenix gravatar image

updated 2015-05-30 06:47:34 -0600

    const uchar* ptr = (const uchar*) (edgeImage.step + row * edgeImage.step);

Definition of uchar:

typedef unsigned char uchar;

Definition of step function:

struct CV_EXPORTS MStep
    {
        MStep();
        MStep(size_t s);
        const size_t& operator[](int i) const;
        size_t& operator[](int i);
        operator size_t() const;
        MStep& operator = (size_t s);

        size_t* p;
        size_t buf[2];
    protected:
        MStep& operator = (const MStep&);
    };

    MStep step;

Definition of size_t: typedef _W64 unsigned int size_t; edgeImage is a MAT type image.

Initially this code was in IplImage format. I converted image from IplImage to Mat and widthstep function to step function (equivalents).

What is the purpose of this code ? When I'm printing *ptr, the compilation props up an error. I once transformed it to this:

int temp= (edgeImage.step + row * edgeImage.step);
const uchar* ptr = (const uchar*) (&temp);

and the error went away. (I think this shows a different value than the initial case and I cant verify it because - the code is too long(StrokeWidthTransform) and it is stuck at a further step in the compilation.)

edit retag flag offensive close merge delete

Comments

I am not sure to understand exactly what you want to achieve (apart from convert an unsigned int to an unsigned char*): convert an IplImage to Mat ?

Eduardo gravatar imageEduardo ( 2015-05-30 10:34:42 -0600 )edit

I have done all the conversions- converting all IplImage objects to Mat objects and finding equivalent functions. I think there is a problem in this version- this kind of definition was working for IplImage objects but is not working on Mat objects. Can u help me in that conversion?

sidPhoenix gravatar imagesidPhoenix ( 2015-05-31 07:27:15 -0600 )edit

So you have some code doing something using the IplImage structure and you want to convert this bunch of code using only the Mat structure ?

widthStep seems to be the width in byte of the image plus some byte padding.

No idead about the purpose of the code:

const uchar* ptr = (const uchar*) (edgeImage.widthStep + row * edgeImage.widthStep);

Or maybe it was:

const uchar* ptr = (const uchar*) (edgeImage.imageData + row * edgeImage.widthStep);

which just permits to go to the pixel location row*width.

Eduardo gravatar imageEduardo ( 2015-05-31 11:18:24 -0600 )edit

But edgeImage is Mat type. I cannot use widthStep or imageData functions for that. I have used their alternatives - (edgeImage.data + row * edgeImage.step) this is working fine. Thanks.

sidPhoenix gravatar imagesidPhoenix ( 2015-06-01 00:16:38 -0600 )edit