0

I am taking in RGB data from my Kinect and trying to put it into an OpenCV matrix. The data is held in "src":

Mat matrixImageRGBA(w, h, CV_8UC4);
memcpy(matrixImageRGBA.data, src, sizeof(byte) * w * h * 4);

However, when I use "imshow" to see the image, it is tiled four time horizontally. I am using the following command:

imshow("Window", matrixImageRGBA);
waitKey(500);

Does anyone have any idea of what the problem may be here? It's driving me nuts.

Thanks!

Matt Kae
  • 147
  • 5
  • How are you getting the Kinect data? It sounds like it's not in the format you specified. – molbdnilo May 08 '17 at 19:26
  • w and h are in the wrong order in the Mat constructor, if w is width and h is height. See http://stackoverflow.com/questions/25642532/opencv-pointx-y-represent-column-row-or-row-column/25644503#25644503 for possible reasons. – Micka May 08 '17 at 21:18

1 Answers1

3

You have w and h backwards. According to the docs the constructor takes the height as the first argument:

Mat (int rows, int cols, int type)      

Also, I would recommend using this constructor:

Mat(int rows, int cols, int type, void *data, size_t step=AUTO_STEP)

instead of copying to the data field (since you are using no padding at the end of each row use the default AUTO_STEP for step).

wcochran
  • 10,089
  • 6
  • 61
  • 69