0

I am having what is follow:

char* imgData;
Scalar scal = cvGet2D(imgData, x, y);

Where Scalar is defined as below:

typedef struct Scalar
{
double val[3];
}
Scalar;

What I want to have a scalar as a result, but without the use of cvGet2D.

How can I implement that?

MelMed
  • 1,702
  • 5
  • 17
  • 25

2 Answers2

0

cvGet2D() must take into account all possible image depths, channel count, etc.
If you know your image format at compile time, you can access the pixels directly via pointer arithmetic.

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
0

Maybe this post will help further:

How do I access a pixel in OpenCV?

In your case is img->imageData simply imgData. To access all your pixels in x and y you still need to know the widthstep (row step) of your image. I would say you have something like:

int x=44;
int y=21;
int widthstep=480;
Scalar pixel = ((Scalar*)imgData)[y*widthstep+x];
Community
  • 1
  • 1
jamk
  • 836
  • 1
  • 10
  • 24