本文整理汇总了C++中INuiFrameTexture类的典型用法代码示例。如果您正苦于以下问题:C++ INuiFrameTexture类的具体用法?C++ INuiFrameTexture怎么用?C++ INuiFrameTexture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了INuiFrameTexture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mat
//Put the kinect imageframe data onto a Mat
Mat* KOCVStream::kFrameToMat(NUI_IMAGE_FRAME* imageFrame){
Mat* frame = new Mat(height, width, CV_8U);
NUI_LOCKED_RECT LockedRect;
//Lock the imageFrame such that kinnect cannot write on it
INuiFrameTexture* texture = imageFrame->pFrameTexture;
texture->LockRect(0, &LockedRect, NULL, 0);
//Get the kinect depth data
BYTE* imageData;
kinect->getDepthData(&LockedRect);
imageData = kinect->dataPix;
//If the data is not empty convert it to Mat
if (LockedRect.Pitch != 0){
/* //Do not do new above!
frame=new Mat(height, width, CV_8U, imageData);
*/
Mat tempMat(height, width, CV_8U, imageData);
tempMat.copyTo(*frame);
}
else{
return new Mat();
}
//Release the frame
texture->UnlockRect(0);
return frame;
};
示例2: WaitForSingleObject
void KinectCam::Nui_GetCamFrame(BYTE *frameBuffer, int frameSize)
{
const NUI_IMAGE_FRAME *pImageFrame = NULL;
WaitForSingleObject(m_hNextVideoFrameEvent, INFINITE);
HRESULT hr = NuiImageStreamGetNextFrame(
m_pVideoStreamHandle,
0,
&pImageFrame );
if( FAILED( hr ) )
{
return;
}
INuiFrameTexture *pTexture = pImageFrame->pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if( LockedRect.Pitch != 0 )
{
BYTE * pBuffer = (BYTE*) LockedRect.pBits;
memcpy(frameBuffer, pBuffer, frameSize);
}
NuiImageStreamReleaseFrame( m_pVideoStreamHandle, pImageFrame );
}
示例3: createRGBImage
int createRGBImage(HANDLE h, IplImage* Color)
{
const NUI_IMAGE_FRAME *pImageFrame = NULL;
HRESULT hr = NuiImageStreamGetNextFrame(h, 1000, &pImageFrame);
if(FAILED(hr))
{
cout << "Create RGB Image Failed\n";
return -1;
}
INuiFrameTexture *pTexture = pImageFrame->pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect(0, &LockedRect, NULL, 0);
if(LockedRect.Pitch != 0)
{
BYTE * pBuffer = (BYTE*)LockedRect.pBits;
cvSetData(Color, pBuffer, LockedRect.Pitch);
cvShowImage("Color Image", Color);
}
NuiImageStreamReleaseFrame(h, pImageFrame);
return 0;
}
示例4: UpdateColor
void SimpleKinect::UpdateColor()
{
HRESULT hr;
NUI_IMAGE_FRAME imageFrame;
hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle, 0, &imageFrame);
if (FAILED(hr))
{
return;
}
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
// Lock the frame data so the Kinect knows not to modify it while we're reading it
pTexture->LockRect(0, &LockedRect, NULL, 0);
// make sure we're receiving real data
if (LockedRect.Pitch == 0)
{
return;
}
// copy current to old
memcpy(m_pPrevRGB, m_pCurrentRGB, LockedRect.size);
// copy in data to current
memcpy(m_pCurrentRGB, LockedRect.pBits, LockedRect.size);
// We're done with the texture so unlock it
pTexture->UnlockRect(0);
// Release the frame
m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle, &imageFrame);
}
示例5: NuiImageStreamGetNextFrame
void KinectSensor::GotDepthAlert( )
{
const NUI_IMAGE_FRAME* pImageFrame = NULL;
HRESULT hr = NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, &pImageFrame);
if (FAILED(hr))
{
return;
}
INuiFrameTexture* pTexture = pImageFrame->pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect(0, &LockedRect, NULL, 0);
if (LockedRect.Pitch)
{ // Copy depth frame to face tracking
memcpy(m_DepthBuffer->GetBuffer(), PBYTE(LockedRect.pBits), min(m_DepthBuffer->GetBufferSize(), UINT(pTexture->BufferLen())));
}
else
{
OutputDebugString( L"Buffer length of received depth texture is bogus\r\n" );
}
hr = NuiImageStreamReleaseFrame(m_pDepthStreamHandle, pImageFrame);
}
示例6: gotColorAlert
//Handles color data
bool Kinect::gotColorAlert()
{
NUI_IMAGE_FRAME frame;
bool processedFrame = true;
//get the next frame from the Kinect
HRESULT hr = globalNui->NuiImageStreamGetNextFrame( videoStreamHandle, 0, &frame);
if (FAILED( hr ) )
{
return false;
}
//get the data we need: frame now also contains information about the kinect it came from, etc. We do not need that.
INuiFrameTexture * texture = frame.pFrameTexture;
NUI_LOCKED_RECT lockedRect;
//lock the data we are going to use, so that other threads cant change it while we are using it.
texture->LockRect( 0, &lockedRect, NULL, 0);
if( lockedRect.Pitch != 0)
{
//draw it to the screen.
//mutex waiting, 5 ms timeout
bitmap->CopyFromMemory(NULL, static_cast<BYTE *>(lockedRect.pBits), 640 * 4);
DWORD result = WaitForSingleObject(mutex,5);
if (result == WAIT_OBJECT_0){
__try {
faceTracker->setColorVars(lockedRect, texture);
}
__finally {
ReleaseMutex(mutex);
}
}
示例7:
UINT16 * Kinect1::getDepthBuffer()
{
int result;
// Grab an image frame
NUI_IMAGE_FRAME imageFrame;
result = sensor->NuiImageStreamGetNextFrame(depthStream, 0, &imageFrame);
// Make sure the frame is not empty
if (result >= 0)
{
// Get frame texture
NUI_LOCKED_RECT lockedRect;
INuiFrameTexture * texture = imageFrame.pFrameTexture;
texture->LockRect(0, &lockedRect, NULL, 0);
UINT16 * bufferIndex = depthBuffer;
UINT16 * frameIndex = (UINT16 *) lockedRect.pBits;
UINT16 * end = frameIndex + (depthWidth * depthHeight);
// Copy data to buffer
while (frameIndex < end)
{
// 4 byte BGRA to 1 int ARGB
*bufferIndex = NuiDepthPixelToDepth(*frameIndex);
bufferIndex++;
frameIndex++;
}
// Release
texture->LockRect(0, &lockedRect, NULL, 0);
sensor->NuiImageStreamReleaseFrame(depthStream, &imageFrame);
}
return depthBuffer;
}
示例8: NuiImageStreamGetNextFrame
int Read_Kinect::drawColor(HANDLE h)
{
const NUI_IMAGE_FRAME * pImageFrame = NULL;
HRESULT hr = NuiImageStreamGetNextFrame(h, 0, &pImageFrame);
if (FAILED(hr))
{
cout << "Get Image Frame Failed" << endl;
return -1;
}
INuiFrameTexture * pTexture = pImageFrame->pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect(0, &LockedRect, NULL, 0);
if (LockedRect.Pitch != 0)
{
BYTE * pBuffer = (BYTE*) LockedRect.pBits;
_color = Mat(COLOR_HIGHT,COLOR_WIDTH,CV_8UC4,pBuffer);
for (int i=0; i<COLOR_HIGHT; i++)
for(int j=0; j<COLOR_WIDTH; j++)
{
_bottom_left_img.at<Vec3b>(i,j).val[0] = _color.at<Vec4b>(i,j).val[0];
_bottom_left_img.at<Vec3b>(i,j).val[1] = _color.at<Vec4b>(i,j).val[1];
_bottom_left_img.at<Vec3b>(i,j).val[2] = _color.at<Vec4b>(i,j).val[2];
}
// imshow("color image", _color);
}
NuiImageStreamReleaseFrame(h, pImageFrame);
return 0;
}
示例9: updateImageFrame
void updateImageFrame( NUI_IMAGE_FRAME& imageFrame, bool isDepthFrame )
{
INuiFrameTexture* nuiTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT lockedRect;
nuiTexture->LockRect( 0, &lockedRect, NULL, 0 );
if ( lockedRect.Pitch!=NULL )
{
const BYTE* buffer = (const BYTE*)lockedRect.pBits;
for ( int i=0; i<480; ++i )
{
const BYTE* line = buffer + i * lockedRect.Pitch;
const USHORT* bufferWord = (const USHORT*)line;
for ( int j=0; j<640; ++j )
{
if ( !isDepthFrame )
{
unsigned char* ptr = colorTexture->bits + 3 * (i * 640 + j);
*(ptr + 0) = line[4 * j + 2];
*(ptr + 1) = line[4 * j + 1];
*(ptr + 2) = line[4 * j + 0];
}
else
setPlayerColorPixel( bufferWord[j], j, i, 255 );
}
}
TextureObject* tobj = (isDepthFrame ? playerColorTexture : colorTexture);
glBindTexture( GL_TEXTURE_2D, tobj->id );
glTexImage2D( GL_TEXTURE_2D, 0, tobj->internalFormat, tobj->width, tobj->height,
0, tobj->imageFormat, GL_UNSIGNED_BYTE, tobj->bits );
}
nuiTexture->UnlockRect( 0 );
}
示例10: Nui_GotColorAlert
bool Nui_GotColorAlert( )
{
NUI_IMAGE_FRAME imageFrame;
bool processedFrame = true;
HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame( m_pVideoStreamHandle, 0, &imageFrame );
if ( FAILED( hr ) )
{
return false;
}
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( LockedRect.Pitch != 0 )
{
memcpy(g_ColorsData, LockedRect.pBits, LockedRect.size);
}
else
{
//OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
processedFrame = false;
}
pTexture->UnlockRect( 0 );
m_pNuiSensor->NuiImageStreamReleaseFrame( m_pVideoStreamHandle, &imageFrame );
return processedFrame;
}
示例11: getRgbData
void getRgbData(GLubyte* dest) {
float* fdest = (float*) dest;
long* depth2rgb = (long*) depthToRgbMap;
NUI_IMAGE_FRAME imageFrame;
NUI_LOCKED_RECT LockedRect;
if (sensor->NuiImageStreamGetNextFrame(rgbStream, 0, &imageFrame) < 0) return;
INuiFrameTexture* texture = imageFrame.pFrameTexture;
texture->LockRect(0, &LockedRect, NULL, 0);
if (LockedRect.Pitch != 0) {
const BYTE* start = (const BYTE*) LockedRect.pBits;
for (int j = 0; j < height; ++j) {
for (int i = 0; i < width; ++i) {
// Determine rgb color for each depth pixel
long x = *depth2rgb++;
long y = *depth2rgb++;
// If out of bounds, then don't color it at all
if (x < 0 || y < 0 || x > width || y > height) {
for (int n = 0; n < 3; ++n) *(fdest++) = 0.0f;
}
else {
const BYTE* curr = start + (x + width*y)*4;
for (int n = 0; n < 3; ++n) *(fdest++) = curr[2-n]/255.0f;
}
}
}
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(rgbStream, &imageFrame);
}
示例12: Nui_GotRgbAlert
void KinectDevice::Nui_GotRgbAlert()
{
NUI_IMAGE_FRAME imageFrame;
HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame(
m_pVideoStreamHandle,
0,
&imageFrame );
if( FAILED( hr ) )
{
return;
}
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if( LockedRect.Pitch != 0 )
{
// TODO:
//cvSetData(iplColor, LockedRect.pBits, iplColor->widthStep);
Mat ref;//(iplColor);
if (_delegate)
_delegate->onRgbData(ref);
isNewFrames[FRAME_COLOR_U8C3] = true;
}
else
{
OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
}
m_pNuiSensor->NuiImageStreamReleaseFrame( m_pVideoStreamHandle, &imageFrame );
}
示例13: getDepthData
void getDepthData(GLubyte* dest) {
float* fdest = (float*) dest;
long* depth2rgb = (long*) depthToRgbMap;
NUI_IMAGE_FRAME imageFrame;
NUI_LOCKED_RECT LockedRect;
if (sensor->NuiImageStreamGetNextFrame(depthStream, 0, &imageFrame) < 0) return;
INuiFrameTexture* texture = imageFrame.pFrameTexture;
texture->LockRect(0, &LockedRect, NULL, 0);
if (LockedRect.Pitch != 0) {
const USHORT* curr = (const USHORT*) LockedRect.pBits;
for (int j = 0; j < height; ++j) {
for (int i = 0; i < width; ++i) {
// Get depth of pixel in millimeters
USHORT depth = NuiDepthPixelToDepth(*curr++);
// Store coordinates of the point corresponding to this pixel
Vector4 pos = NuiTransformDepthImageToSkeleton(i, j, depth<<3, NUI_IMAGE_RESOLUTION_640x480);
*fdest++ = pos.x/pos.w;
*fdest++ = pos.y/pos.w;
*fdest++ = pos.z/pos.w;
// Store the index into the color array corresponding to this pixel
NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution(
NUI_IMAGE_RESOLUTION_640x480, NUI_IMAGE_RESOLUTION_640x480, NULL,
i, j, depth<<3, depth2rgb, depth2rgb+1);
depth2rgb += 2;
}
}
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(depthStream, &imageFrame);
}
示例14: ProcessColor
/// <summary>
/// Handle new color data
/// </summary>
/// <returns>S_OK for success or error code</returns>
HRESULT KinectEasyGrabber::ProcessColor()
{
HRESULT hr = S_OK;
NUI_IMAGE_FRAME imageFrame;
// Attempt to get the depth frame
hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle, 0, &imageFrame);
if (FAILED(hr))
{
return hr;
}
m_colorTimeStamp = imageFrame.liTimeStamp;
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
// Lock the frame data so the Kinect knows not to modify it while we're reading it
pTexture->LockRect(0, &LockedRect, NULL, 0);
// Make sure we've received valid data
if (LockedRect.Pitch != 0)
{
memcpy(m_colorRGBX, LockedRect.pBits, LockedRect.size);
}
// We're done with the texture so unlock it
pTexture->UnlockRect(0);
// Release the frame
m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle, &imageFrame);
return hr;
}
示例15: ProcessColor
/// <summary>
/// Handle new color data
/// </summary>
/// <returns>indicates success or failure</returns>
void CDataCollection::ProcessColor()
{
HRESULT hr;
NUI_IMAGE_FRAME imageFrame;
//DEBUG("Process color!\n");
// Attempt to get the color frame
hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle, 0, &imageFrame);
if (FAILED(hr))
{
return;
}
INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
// Lock the frame data so the Kinect knows not to modify it while we're reading it
pTexture->LockRect(0, &LockedRect, NULL, 0);
// Make sure we've received valid data
if (LockedRect.Pitch != 0)
{
// Draw the data with Direct2D
m_pDrawColor->Draw(static_cast<BYTE *>(LockedRect.pBits), LockedRect.size);
}
// We're done with the texture so unlock it
pTexture->UnlockRect(0);
// Release the frame
m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle, &imageFrame);
}