• 大小: 9.6MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-11-05
  • 语言: 其他
  • 标签: Kinect  

资源简介

利用Kinect sdk2.0和opencv,获取深度图和彩色图,并实时显示。 详见博文http://blog.csdn.net/hust_bochu_xuchao/article/details/53665838 代码下载后可直接运行

资源截图

代码片段和文件信息

//------------------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//------------------------------------------------------------------------------

#include “stdafx.h“
#include “ImageRenderer.h“

/// 
/// Constructor
/// 

ImageRenderer::ImageRenderer() : 
    m_hWnd(0)
    m_sourceWidth(0)
    m_sourceHeight(0)
    m_sourceStride(0)
    m_pD2DFactory(NULL) 
    m_pRenderTarget(NULL)
    m_pBitmap(0)
{
}

/// 
/// Destructor
/// 

ImageRenderer::~ImageRenderer()
{
    DiscardResources();
    SafeRelease(m_pD2DFactory);
}

/// 
/// Ensure necessary Direct2d resources are created
/// 

/// indicates success or failure
HRESULT ImageRenderer::EnsureResources()
{
    HRESULT hr = S_OK;

    if (NULL == m_pRenderTarget)
    {
        D2D1_SIZE_U size = D2D1::SizeU(m_sourceWidth m_sourceHeight);

        D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties();
        rtProps.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM D2D1_ALPHA_MODE_IGNORE);
        rtProps.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;

        // Create a hWnd render target in order to render to the window set in initialize
        hr = m_pD2DFactory->CreateHwndRenderTarget(
            rtProps
            D2D1::HwndRenderTargetProperties(m_hWnd size)
            &m_pRenderTarget
        );

        if (FAILED(hr))
        {
            return hr;
        }

        // Create a bitmap that we can copy image data into and then render to the target
        hr = m_pRenderTarget->CreateBitmap(
            size 
            D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM D2D1_ALPHA_MODE_IGNORE))
            &m_pBitmap 
        );

        if (FAILED(hr))
        {
            SafeRelease(m_pRenderTarget);
            return hr;
        }
    }

    return hr;
}

/// 
/// Dispose of Direct2d resources 
/// 

void ImageRenderer::DiscardResources()
{
    SafeRelease(m_pRenderTarget);
    SafeRelease(m_pBitmap);
}

/// 
/// Set the window to draw to as well as the video format
/// Implied bits per pixel is 32
/// 

/// window to draw to
/// already created D2D factory object
/// width (in pixels) of image data to be drawn
/// height (in pixels) of image data to be drawn
/// length (in bytes) of a single scanline
/// indicates success or failure
HRESULT ImageRenderer::Initialize(HWND hWnd ID2D1Factory* pD2DFactory int sourceWidth int sourceHeight int sourceStride)
{
    if (NULL == pD2

评论

共有 条评论