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!
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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.