資源簡介
《Kinect for Windows SDK v2 0 開發(fā)筆記 九 面部幀獲取》所附帶資源
代碼片段和文件信息
#include?“stdafx.h“
#include?“included.h“
#include?
#define?PI_F???????3.1415926f
static?const?WCHAR*?FACE_TEXT?=?LR“face_text(面部旋轉(zhuǎn):
????Picth:?%03.03f
????Yaw:?%03.03f
????Roll:?%03.03f
面部屬性:
????表情高興:?%s
????Engaged:?%s
????戴著眼鏡:?%s
????左眼閉著:?%s
????右眼閉著:?%s
????張著嘴巴:?%s
????嘴巴在動:?%s
????看著一邊:?%s
)face_text“;
static?const?WCHAR*?RRSULT_TEXT[]?=?{
????L“未知“
????L“確定不“
????L“不確定“
????L“確定“
};
//?ImageRender類構(gòu)造函數(shù)
ImageRenderer::ImageRenderer(){
????ZeroMemory(face_data?sizeof(face_data));
//?創(chuàng)建資源
m_hrInit?=?CreateDeviceIndependentResources();
????//?創(chuàng)建緩沖區(qū)
????m_pColorRGBX?=?new?RGBQUAD[IMAGE_WIDTH*IMAGE_HEIGHT];
????if?(!m_pColorRGBX)?m_hrInit?=?E_OUTOFMEMORY;
????m_timer.Start();
}
//?創(chuàng)建設(shè)備無關(guān)資源
HRESULT?ImageRenderer::CreateDeviceIndependentResources(){
HRESULT?hr?=?S_OK;
//?創(chuàng)建?Direct2D?工廠.
hr?=?D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED?&m_pD2DFactory);
if?(SUCCEEDED(hr))
{
//?創(chuàng)建?WIC?工廠.
hr?=?CoCreateInstance(
CLSID_WICImagingFactory
NULL
CLSCTX_INPROC_SERVER
IID_IWICImagingFactory
reinterpret_cast(&m_pWICFactory)
);
}
if?(SUCCEEDED(hr))
{
//?創(chuàng)建?DirectWrite?工廠.
hr?=?DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED
__uuidof(m_pDWriteFactory)
reinterpret_cast(&m_pDWriteFactory)
);
}
if?(SUCCEEDED(hr))
{
//?創(chuàng)建正文文本格式.
hr?=?m_pDWriteFactory->CreateTextFormat(
L“Microsoft?YaHei“
nullptr
DWRITE_FONT_WEIGHT_NORMAL
DWRITE_FONT_style_NORMAL
DWRITE_FONT_STRETCH_NORMAL
45.f
L““?//locale
&m_pTextFormatMain
);
}
return?hr;
}
//?從文件讀取位圖
HRESULT?ImageRenderer::LoadBitmapFromFile(
ID2D1RenderTarget?*pRenderTarget
IWICImagingFactory?*pIWICFactory
PCWSTR?uri
UINT?destinationWidth
UINT?destinationHeight
ID2D1Bitmap?**ppBitmap
)
{
IWICBitmapDecoder?*pDecoder?=?NULL;
IWICBitmapframeDecode?*pSource?=?NULL;
IWICStream?*pStream?=?NULL;
IWICFormatConverter?*pConverter?=?NULL;
IWICBitmapScaler?*pScaler?=?NULL;
HRESULT?hr?=?pIWICFactory->CreateDecoderFromFilename(
uri
NULL
GENERIC_READ
WICDecodemetadataCacheonload
&pDecoder
);
if?(SUCCEEDED(hr))
{
hr?=?pDecoder->Getframe(0?&pSource);
}
if?(SUCCEEDED(hr))
{
hr?=?pIWICFactory->CreateFormatConverter(&pConverter);
}
if?(SUCCEEDED(hr))
{
if?(destinationWidth?!=?0?||?destinationHeight?!=?0)
{
UINT?originalWidth?originalHeight;
hr?=?pSource->GetSize(&originalWidth?&originalHeight);
if?(SUCCEEDED(hr))
{
if?(destinationWidth?==?0)
{
FLOAT?scalar?=?static_cast(destinationHeight)?/?static_cast(originalHeight);
destinationWidth?=?static_cast(scalar?*?static_cast(originalWidth));
}
else?if?(destinationHeight?==?0)
{
FLOAT?scalar?=?static_cast(destinationWidth)?/?static_cast(originalWidth);
destination
- 上一篇:卡巴斯基60天試用key
- 下一篇:ArcGIS Server 10.3 破解文件
評論
共有 條評論