当我尝试将kinect的深度图像与彩色图像对齐时,彩色图像质量很差 [英] Color image having poor quality when I tried to align kinect's depth image with color image
本文介绍了当我尝试将kinect的深度图像与彩色图像对齐时,彩色图像质量很差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我尝试通过NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution函数将深度图像与彩色图像对齐,但新的彩色图像质量不佳。 这是一个例子:
I tried to align the depth image with color image by means of NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution function but the new color image doesn't have a good quality. Here's an example:
这里是代码:
bool CSkeletalViewerApp::Nui_GotDepthAlert( )
{
NUI_IMAGE_FRAME imageFrame;
bool processedFrame = true;
HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame(
m_pDepthStreamHandle,
0,
&imageFrame );
if ( FAILED( hr ) )
{
return false;
}
m_depthTimeStamp = imageFrame.liTimeStamp;
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( 0 != LockedRect.Pitch )
{
//memcpy(m_depthD16, LockedRect.pBits, LockedRect.size);
DWORD frameWidth, frameHeight;
NuiImageResolutionToSize( imageFrame.eResolution, frameWidth, frameHeight );
// draw the bits to the bitmap
BYTE * rgbrun = m_depthRGBX;
const USHORT * pBufferRun = (const USHORT *)LockedRect.pBits;
……..
m_pDrawDepth->Draw( m_depthRGBX, frameWidth * frameHeight * g_BytesPerPixel );
USHORT* depth2=(USHORT *)m_depthRGBX;
m_pNuiSensor->NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution(
NUI_IMAGE_RESOLUTION_640x480,
NUI_IMAGE_RESOLUTION_640x480,
m_depthWidth*m_depthHeight,
//m_depthD16,
depth2,
m_depthWidth*m_depthHeight*2,
m_colorCoordinates
);
}
….
}
bool CSkeletalViewerApp::Nui_GotColorAlert( )
{
NUI_IMAGE_FRAME imageFrame;
bool processedFrame = true;
HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame( m_pVideoStreamHandle, 0, &imageFrame );
if ( FAILED( hr ) )
{
return false;
}
m_colorTimeStamp = imageFrame.liTimeStamp;
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( LockedRect.Pitch != 0 )
{
colorData = (USHORT *)LockedRect.pBits;
m_pDrawColor->Draw( static_cast<BYTE *>(LockedRect.pBits), LockedRect.size );
}
else
{
OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
processedFrame = false;
}
pTexture->UnlockRect( 0 );
if(m_pVideoStreamHandle!=NULL)
m_pNuiSensor->NuiImageStreamReleaseFrame( m_pVideoStreamHandle, &imageFrame );
return processedFrame;
}
DWORD WINAPI CSkeletalViewerApp::Nui_ProcessThread( )
{
......
if(needToDraw)
{
int outputIndex = 0;
LONG* pDest;
LONG* pSrc;
// loop over each row and column of the color
for (LONG y = 0; y < m_colorHeight; ++y)
{
pDest = (LONG*) mappedData + (y * 640);
for (LONG x = 0; x < m_colorWidth; ++x)
{
// calculate index into depth array
int depthIndex = x/m_colorToDepthDivisor + y/m_colorToDepthDivisor * m_depthWidth;
//int depthIndex = x + y * 640;
// retrieve the depth to color mapping for the current depth pixel
LONG colorInDepthX = m_colorCoordinates[depthIndex * 2];
LONG colorInDepthY = m_colorCoordinates[depthIndex * 2 + 1];
// make sure the depth pixel maps to a valid point in color space
if ( colorInDepthX >= 0 && colorInDepthX < m_colorWidth && colorInDepthY >= 0 && colorInDepthY < m_colorHeight )
{
// calculate index into color array
LONG colorIndex = colorInDepthX + colorInDepthY * m_colorWidth;
// set source for copy to the color pixel
pSrc = (LONG*)(rgb1) + colorIndex; // (LONG *)m_colorRGBX + colorIndex;
}
// calculate output pixel location
pDest = (LONG *)m_outputRGBX + outputIndex++;
// write output
*pDest = *pSrc;
}
}
IplImage* color = cvCreateImageHeader(cvSize(640, 480), 8, 4);
cvSetData(color, static_cast<BYTE *>(m_outputRGBX), color->widthStep);
Mat m2(color);
IplImage iplimg1(m2);
cvNamedWindow("RGB3",1);
cvShowImage("RGB3",&iplimg1);
waitKey(1);
}
.....
}
有人能告诉我这是什么问题吗?
Could someone tell me what is the problem?
谢谢
推荐答案
您正在使用弃用的api。使用坐标映射器。
You are using deprecated api's. Use the coordinate mapper.
这篇关于当我尝试将kinect的深度图像与彩色图像对齐时,彩色图像质量很差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文