我試圖讓Kinect深度相機像素覆蓋到RGB相機上。我正在使用帶有Xbox Kinect,OpenCV的C++ Kinect 1.0 SDK,並嘗試使用新的「NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution」方法。使用Kinect 1.0 SDK對RGB圖像進行深度圖像故障修正
我看過圖像渲染本身在慢動作,看起來好像是在一個幀中多次繪製像素。它首先從頂部和左側的邊界繪製自己,然後到達一個點(您可以在那裏看到一個45度角),它開始畫出奇怪的地方。
我一直在試圖將我的代碼從亞當斯密寫在MSDN forums的C#代碼中,但沒有骰子。我已經剝離了覆蓋層的東西,只是想繪製RGB圖像中「應該」的深度標準化深度像素。
左邊的圖像是我在嘗試將深度圖像適合RGB空間時獲得的圖像,而右邊的圖像是我喜歡看到的「原始」深度圖像。我希望這種方法能夠產生與右側圖像相似的圖像,並略有扭曲。
這是代碼和對象定義,我都不得不時刻:
// From initialization
INuiSensor *m_pNuiInstance;
NUI_IMAGE_RESOLUTION m_nuiResolution = NUI_IMAGE_RESOLUTION_640x480;
HANDLE m_pDepthStreamHandle;
IplImage *m_pIplDepthFrame;
IplImage *m_pIplFittedDepthFrame;
m_pIplDepthFrame = cvCreateImage(cvSize(640, 480), 8, 1);
m_pIplFittedDepthFrame = cvCreateImage(cvSize(640, 480), 8, 1);
// Method
IplImage *Kinect::GetRGBFittedDepthFrame() {
static long *pMappedBits = NULL;
if (!pMappedBits) {
pMappedBits = new long[640*480*2];
}
NUI_IMAGE_FRAME pNuiFrame;
NUI_LOCKED_RECT lockedRect;
HRESULT hr = m_pNuiInstance->NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, &pNuiFrame);
if (FAILED(hr)) {
// return the older frame
return m_pIplFittedDepthFrame;
}
bool hasPlayerData = HasSkeletalEngine(m_pNuiInstance);
INuiFrameTexture *pTexture = pNuiFrame.pFrameTexture;
pTexture->LockRect(0, &lockedRect, NULL, 0);
if (lockedRect.Pitch != 0) {
cvZero(m_pIplFittedDepthFrame);
hr = m_pNuiInstance->NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution(
m_nuiResolution,
NUI_IMAGE_RESOLUTION_640x480,
640 * 480, /* size is previous */ (unsigned short*) lockedRect.pBits,
(640 * 480) * 2, /* size is previous */ pMappedBits);
if (FAILED(hr)) {
return m_pIplFittedDepthFrame;
}
for (int i = 0; i < lockedRect.size; i++) {
unsigned char* pBuf = (unsigned char*) lockedRect.pBits + i;
unsigned short* pBufS = (unsigned short*) pBuf;
unsigned short depth = hasPlayerData ? ((*pBufS) & 0xfff8) >> 3 : ((*pBufS) & 0xffff);
unsigned char intensity = depth > 0 ? 255 - (unsigned char) (256 * depth/0x0fff) : 0;
long
x = pMappedBits[i], // tried with *(pMappedBits + (i * 2)),
y = pMappedBits[i + 1]; // tried with *(pMappedBits + (i * 2) + 1);
if (x >= 0 && x < m_pIplFittedDepthFrame->width && y >= 0 && y < m_pIplFittedDepthFrame->height) {
m_pIplFittedDepthFrame->imageData[x + y * m_pIplFittedDepthFrame->widthStep] = intensity;
}
}
}
pTexture->UnlockRect(0);
m_pNuiInstance->NuiImageStreamReleaseFrame(m_pDepthStreamHandle, &pNuiFrame);
return(m_pIplFittedDepthFrame);
}
感謝
你只打開深度數據流? – 2012-08-14 08:59:20
顏色流也被打開。雖然我不確定是否需要。 – 2012-08-15 09:48:14