0
votes

I'm making kind of an histogram stored in a Matrix on OpenCV.

So, if I match one result, I will at +1 on some index.

My mat is:

Mat countFramesMatrix = Mat::zeros(9,9,CV_8U);

when I try to access to sum +1 to the already set index (from 0), I do:

int valueMatrixFrames = countFramesMatrix.at<int>(sliceMatch.j, sliceMatch.i);
valueMatrixFrames++;
countFramesMatrix.at<unsigned char>(sliceMatch.j, sliceMatch.i) = (unsigned char)valueMatrixFrames;

I tried in other ways, as changing unsigned char for int an other problems I had before, but nothing happens.

My results are:

  1. Or all the matrix is zeros.
  2. Or I get something like:

    [2.3693558e-38, 0, 0, 0, 0, 0, 0, 0, 0; 2.3693558e-38, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0]

And I'm never storing data at (0,0) or (0,1) or (1,0) or (1,1), :(

What would you suggest? thank you.

1
How is declared countFramesMatrix ? You access to this matrix sometime telling the compiler this is a matrix of int, sometime telling it is a matrix of char. Technically, this is not forbiden to do so, but I doubt this is what you are trying to do.biquette

1 Answers

1
votes

You are misting a very simple mistake,

valueMatrixFrames++;

will increment value of valueMatrixFrames, not of the matrix location.

RIGHT WAY

Let's say, if you want to increment at (1,1) you should use,

countFramesMatrix.at<uchar>(1,1)++;

OUTPUT

 [0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 1, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0]

Running the above command again will increment the value at (1, 1) to 2.

 [0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 2, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 0, 0, 0, 0, 0]

So, your histogram is ready!!