Arp*_*wal 5 opencv kinect kinect-sdk
我一直在使用Kinect SDK(1.6)DepthBasicsD2D C++示例从kinect获取深度帧,并希望在OpenCV中使用数据执行blob检测.
我已经使用示例配置了OpenCV,并且还了解了示例的基本工作.
但不知怎的,在任何地方都没有任何帮助,很难弄清楚如何从Kinect获取像素数据并传递给OpenCV的IplImage/cv :: Mat结构.
有没有想过这个问题?
这可以帮助您将 kinect 颜色和深度图像以及深度图像转换为 OpenCV 表示形式:
// get a CV_8U matrix from a Kinect depth frame
cv::Mat * GetDepthImage(USHORT * depthData, int width, int height)
{
const int imageSize = width * height;
cv::Mat * out = new cv::Mat(height, width, CV_8U) ;
// map the values to the depth range
for (int i = 0; i < imageSize; i++)
{
// get the lower 8 bits
USHORT depth = depthData[i];
if (depth >= kLower && depth <= kUpper)
{
float y = c * (depth - kLower);
out->at<byte>(i) = (byte) y;
}
else
{
out->at<byte>(i) = 0;
}
}
return out;
};
// get a CV_8UC4 (RGB) Matrix from Kinect RGB frame
cv::Mat * GetColorImage(unsigned char * bytes, int width, int height)
{
const unsigned int img_size = width * height * 4;
cv::Mat * out = new cv::Mat(height, width, CV_8UC4);
// copy data
memcpy(out->data, bytes, img_size);
return out;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4704 次 |
| 最近记录: |