本文整理汇总了C++中INuiFrameTexture::UnlockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ INuiFrameTexture::UnlockRect方法的具体用法?C++ INuiFrameTexture::UnlockRect怎么用?C++ INuiFrameTexture::UnlockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INuiFrameTexture
的用法示例。
在下文中一共展示了INuiFrameTexture::UnlockRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertDepthFrameToArray
void ConvertDepthFrameToArray(const NUI_IMAGE_FRAME& frame, DataTypes::DepthImage& image)
{
assert(frame.eImageType == NUI_IMAGE_TYPE_DEPTH);
assert(frame.eResolution == NUI_IMAGE_RESOLUTION_640x480);
INuiFrameTexture* texture = frame.pFrameTexture;
NUI_LOCKED_RECT lockedRect;
// Lock the frame data so the Kinect knows not to modify it while we're reading it
texture->LockRect(0, &lockedRect, NULL, 0);
{
// Make sure we've received valid data
if (lockedRect.Pitch == 0)
{
texture->UnlockRect(0);
throw -1;
}
//////////////////////////////
assert((lockedRect.size % sizeof(short)) == 0);
assert((lockedRect.Pitch % sizeof(short)) == 0);
int cols = lockedRect.Pitch / sizeof(short);
int rows = lockedRect.size / lockedRect.Pitch;
memcpy(depthData, lockedRect.pBits, lockedRect.size);
int byteNum = 0;
for(int y=0; y<rows; y++)
{
for(int x=0; x<cols; x++)
{
const unsigned short& pixel = (unsigned short&)lockedRect.pBits[byteNum];
DepthPixel& depth = image.data[y][x];
// discard the portion of the depth that contains only the player index
depth = NuiDepthPixelToDepth(pixel);
byteNum += sizeof(short);
}
}
image.rows = rows;
image.cols = cols;
//////////////////////////////
}
// We're done with the texture so unlock it
texture->UnlockRect(0);
return;
}
示例2: ConvertColorFrameToArray
void ConvertColorFrameToArray(const NUI_IMAGE_FRAME& frame, DataTypes::ColorImage& image)
{
assert(frame.eImageType == NUI_IMAGE_TYPE_COLOR);
assert(frame.eResolution == NUI_IMAGE_RESOLUTION_640x480);
INuiFrameTexture* texture = frame.pFrameTexture;
NUI_LOCKED_RECT lockedRect;
// Lock the frame data so the Kinect knows not to modify it while we're reading it
texture->LockRect(0, &lockedRect, NULL, 0);
{
// Make sure we've received valid data
if (lockedRect.Pitch == 0)
{
texture->UnlockRect(0);
throw -1;
}
//////////////////////////////
assert((lockedRect.size % 4) == 0);
assert((lockedRect.Pitch % 4) == 0);
int cols = lockedRect.Pitch / 4;
int rows = lockedRect.size / lockedRect.Pitch;
int byteNum = 0;
for(int y=0; y<rows; y++)
{
for(int x=0; x<cols; x++)
{
const RgbPixel& pixel = (RgbPixel&)lockedRect.pBits[byteNum];
ColorPixel& color = image.data[y][x];
color.red = pixel.red();
color.green = pixel.green();
color.blue = pixel.blue();
byteNum += 4;
}
}
image.rows = rows;
image.cols = cols;
//////////////////////////////
}
// We're done with the texture so unlock it
texture->UnlockRect(0);
return;
}
示例3: 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 );
}
示例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: kFrameToMat
//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;
};
示例6: 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);
}
示例7: 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);
}
示例8: 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;
}
示例9:
ci::gl::Texture *moduleCapture::getNextFrame()
{
HRESULT hr = sensor->NuiImageStreamGetNextFrame(colorStreamHandle, 0, pColorImageFrame); // Obtiene el siguiente frame del kinect
if (FAILED(hr)){
return NULL; // Si habia error, retorna NULL
}
INuiFrameTexture *colorTexture = pColorImageFrame->pFrameTexture;
NUI_LOCKED_RECT *colorRect = new NUI_LOCKED_RECT;
colorTexture->LockRect( 0, colorRect, 0, 0 );
if(colorRect->Pitch == 0){
return NULL;
}
// Crea un gl::Texture con los datos del frame
uint8_t *buffer = colorRect->pBits;
int size = resolution.width * resolution.height * 4;
ci::gl::Texture *texture = new ci::gl::Texture(buffer, GL_BGRA, resolution.width, resolution.height);
colorTexture->UnlockRect(0);
// Libera el frame del kinect
sensor->NuiImageStreamReleaseFrame(colorStreamHandle, pColorImageFrame);
// Retorna la textura
return texture;
}
示例10: 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);
}
示例11: getKinectData
void getKinectData(int* data) {
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;
const USHORT* dataEnd = curr + (width*height);
while (curr < dataEnd) {
//Get Depth in mm
USHORT depth = NuiDepthPixelToDepth(*curr++);
//Insert code to build a 640x480 matrix
for (int i = 0; i= height*width - 1; ++i){
*data++ = depth;
}
}
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(depthStream, &imageFrame);
}
示例12: 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;
}
示例13: nextDepthFrame
void nextDepthFrame ()
{
NUI_IMAGE_FRAME depthFrame;
WinRet ret = sensor->NuiImageStreamGetNextFrame(depthStreamHandle, 0, &depthFrame);
if (FAILED(ret))
return;
BOOL nearModeOperational = false;
INuiFrameTexture* texture = 0;
ret = sensor->NuiImageFrameGetDepthImagePixelFrameTexture(depthStreamHandle, &depthFrame, &nearModeOperational, &texture);
if (FAILED(ret))
return;
NUI_LOCKED_RECT lockedRect;
texture->LockRect(0, &lockedRect, NULL, 0);
if (0 != lockedRect.Pitch)
{
NUI_SURFACE_DESC surfaceDesc;
texture->GetLevelDesc(0, &surfaceDesc);
const int width = surfaceDesc.Width;
const int height = surfaceDesc.Height;
NUI_DEPTH_IMAGE_PIXEL* extended_buf = reinterpret_cast<NUI_DEPTH_IMAGE_PIXEL*>(lockedRect.pBits);
ntk_assert(width == that->m_current_image.rawDepth16bits().cols, "Bad width");
ntk_assert(height == that->m_current_image.rawDepth16bits().rows, "Bad height");
if (that->m_align_depth_to_color)
{
QWriteLocker locker(&that->m_lock);
uint16_t* depth_buf = that->m_current_image.rawDepth16bitsRef().ptr<uint16_t>();
mapDepthFrameToRgbFrame(extended_buf, depth_buf);
}
else
{
QWriteLocker locker(&that->m_lock);
uint16_t* depth_buf = that->m_current_image.rawDepth16bitsRef().ptr<uint16_t>();
cv::Vec2w* depth_to_color_coords = that->m_current_image.depthToRgbCoordsRef().ptr<cv::Vec2w>();
extractDepthAndColorCoords (extended_buf, depth_buf, depth_to_color_coords);
}
}
else
{
debug(L"Buffer length of received texture is bogus\r\n");
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(depthStreamHandle, &depthFrame);
dirtyDepth = false;
}
示例14: ProcessColor
/// <summary>
/// Process the incoming color frame
/// </summary>
void NuiColorStream::ProcessColor()
{
HRESULT hr;
NUI_IMAGE_FRAME imageFrame;
// Attempt to get the color frame
hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_hStreamHandle, 0, &imageFrame);
if (FAILED(hr))
{
return;
}
if (m_paused)
{
// Stream paused. Skip frame process and release the frame.
goto ReleaseFrame;
}
INuiFrameTexture* pTexture = imageFrame.pFrameTexture;
// Lock the frame data so the Kinect knows not to modify it while we are reading it
NUI_LOCKED_RECT lockedRect;
pTexture->LockRect(0, &lockedRect, NULL, 0);
// Make sure we've received valid data
if (lockedRect.Pitch != 0)
{
switch (m_imageType)
{
case NUI_IMAGE_TYPE_COLOR_RAW_BAYER: // Convert raw bayer data to color image and copy to image buffer
m_imageBuffer.CopyBayer(lockedRect.pBits, lockedRect.size);
break;
case NUI_IMAGE_TYPE_COLOR_INFRARED: // Convert infrared data to color image and copy to image buffer
m_imageBuffer.CopyInfrared(lockedRect.pBits, lockedRect.size);
break;
default: // Copy color data to image buffer
m_imageBuffer.CopyRGB(lockedRect.pBits, lockedRect.size);
break;
}
if (m_pStreamViewer)
{
// Set image data to viewer
m_pStreamViewer->SetImage(&m_imageBuffer);
}
}
// Unlock frame data
pTexture->UnlockRect(0);
ReleaseFrame:
m_pNuiSensor->NuiImageStreamReleaseFrame(m_hStreamHandle, &imageFrame);
}
示例15: Update
/// <summary>
/// Main processing function
/// </summary>
void CSkeletonBasics::Update()
{
if (NULL == m_pNuiSensor)
{
return;
}
// Wait for 0ms, just quickly test if it is time to process a skeleton
if ( WAIT_OBJECT_0 == WaitForSingleObject(m_hNextSkeletonEvent, 0) )
{
ProcessSkeleton();
}
if (WAIT_OBJECT_0 == WaitForSingleObject(hColorEvent, 0))
{
// Colorカメラからフレームを取得
hResult = m_pNuiSensor->NuiImageStreamGetNextFrame(hColorHandle, 0, &colorImageFrame);
if (FAILED(hResult)) {
std::cout << "Error : NuiImageStreamGetNextFrame( COLOR )" << std::endl;
return;
}
if (shutter == 1) {
// Color画像データの取得
INuiFrameTexture* pColorFrameTexture = colorImageFrame.pFrameTexture;
NUI_LOCKED_RECT colorLockedRect;
pColorFrameTexture->LockRect(0, &colorLockedRect, nullptr, 0);
// Retrieve the path to My Photos
WCHAR screenshotPath[MAX_PATH];
GetScreenshotFileName(screenshotPath, _countof(screenshotPath));
// Write out the bitmap to disk
hResult = SaveBitmapToFile(static_cast<BYTE *>(colorLockedRect.pBits), 640, 480, 32, screenshotPath);
if (SUCCEEDED(hResult))
{
std::cout << "saved" << std::endl;
}
else
{
std::cout << "unsave!!" << std::endl;
}
// フレームの解放
pColorFrameTexture->UnlockRect(0);
shutter = 0;
}
//リリース
pNuiSensor->NuiImageStreamReleaseFrame(hColorHandle, &colorImageFrame);
}
}