我有一个简单的问题:
我讨厌将RGB图片存储在数组中,并希望将其存储到cv:Mat中。
我已经用Kinect传感器的深度图像做到了这一点:
VideoFrameRef lDepthFrame;
lStatus = gDepthVideoStream.readFrame(&lDepthFrame);
cv::Mat lDepthMat(lDepthFrame.getHeight(), lDepthFrame.getWidth(), CV_16U, (uint16_t*)lDepthFrame.getData());我现在的问题是我找不到对彩色图像使用哪种类型(上面我使用的是CV_16U)。彩色图像格式为RGB888/RGB24。所以它有3个字节大,每种颜色一个字节。
所以我的彩色图像是这样的:
VideoFrameRef lColorFrame;
lStatus = gRgbVideoStream.readFrame(&lColorFrame);
cv::Mat lRgbMat(lColorFrame.getHeight(), lColorFrame.getWidth(), <????>, (<????>*)lColorFrame.getData());要使此函数工作,我需要替换上面代码中的。
非常感谢你的阅读,希望你能回答我。如果这里有太多的拼写错误,我真的很抱歉我的英语。我绝不是说母语的人。
发布于 2014-06-03 23:21:08
RGB888在opencv中是CV_8UC3,8位无符号值,有3个通道。
如果RGB实际上是BGR,可能会有问题-但您可以稍后交换频道。
发布于 2017-08-22 18:34:28
你可以做一些像这样简单的事情:
IColorFrame* pColorFrame = nullptr;
cv::Mat image;
if (SUCCEEDED(m_pColorFrameReader->AcquireLatestFrame(&pColorFrame)) {
// First you probably would like to get the image dimensions coming from your kinect device
IFrameDescription* pFrameDescription = nullptr;
int nWidth = 0;
int nHeight = 0;
pColorFrame->get_FrameDescription(&pFrameDescription);
pFrameDescription->get_Width(&nWidth);
pFrameDescription->get_Height(&nHeight);
// now you just need to allocate your opencv matrix and copy the data from the IColorFrame object
imageData.create(nHeight, nWidth , CV_8UC4);
BYTE* imgDataPtr = (BYTE*)imageData.data;
pColorFrame->CopyConvertedFrameDataToArray(nWidth * nHeight * 4, imgDataPtr, ColorImageFormat_Bgra);
// release your pointer
pFrameDescription->Release();
pFrameDescription = nullptr;
}
pColorFrame->Release();
pColorFrame = nullptr;然后,您可以简单地使用opencv方法来显示图像;
cv::imshow("Kinect Image", image);https://stackoverflow.com/questions/24016315
复制相似问题