本文整理汇总了C++中xn::DepthMetaData类的典型用法代码示例。如果您正苦于以下问题:C++ DepthMetaData类的具体用法?C++ DepthMetaData怎么用?C++ DepthMetaData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DepthMetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getDepthHistgram
// デプスのヒストグラムを作成
depth_hist getDepthHistgram(const xn::DepthGenerator& depth,
const xn::DepthMetaData& depthMD)
{
// デプスの傾向を計算する(アルゴリズムはNiSimpleViewer.cppを利用)
const int MAX_DEPTH = depth.GetDeviceMaxDepth();
depth_hist depthHist(MAX_DEPTH);
unsigned int points = 0;
const XnDepthPixel* pDepth = depthMD.Data();
for (XnUInt y = 0; y < depthMD.YRes(); ++y) {
for (XnUInt x = 0; x < depthMD.XRes(); ++x, ++pDepth) {
if (*pDepth != 0) {
depthHist[*pDepth]++;
points++;
}
}
}
for (int i = 1; i < MAX_DEPTH; ++i) {
depthHist[i] += depthHist[i-1];
}
if ( points != 0) {
for (int i = 1; i < MAX_DEPTH; ++i) {
depthHist[i] =
(unsigned int)(256 * (1.0f - (depthHist[i] / points)));
}
}
return depthHist;
}
示例2: GenerateMinecraftCharacter
int GenerateMinecraftCharacter(const xn::DepthMetaData& dmd, const xn::SceneMetaData& smd, const XnRGB24Pixel* image)
{
int ret = 0;
int xRes = dmd.XRes();
int yRes = dmd.YRes();
cv::Mat inputImage = cv::Mat(yRes, xRes, CV_8UC3);
cv::Mat skin = cv::Mat::zeros(cv::Size(64,32), CV_8UC3);
XnToCV(image,&inputImage);
cv::cvtColor(inputImage,inputImage,CV_RGB2BGR);
XnUserID aUsers[15];
XnUInt16 nUsers = 15;
g_UserGenerator.GetUsers(aUsers, nUsers);
int i = 0;
for (i = 0; i < nUsers; ++i) {
if (g_UserGenerator.GetSkeletonCap().IsTracking(aUsers[i])) break;
}
// No users being tracked
if (i == nUsers) return -1;
ret = GenerateSkin(aUsers[i], &inputImage, &skin);
printf("GenerateSkin returned %d on user %d\n",ret,(int)aUsers[i]);
cv::imwrite("skin.png",skin);
SegmentUser(aUsers[i], &inputImage, smd);
DrawDebugPoints(aUsers[i], &inputImage);
cv::imwrite("blah.png",inputImage);
sync();
system("convert skin.png -transparent black skin.png && composite -geometry +32+0 hardhat.png skin.png skin.png");
sync();
return ret;
}
示例3: getDepthImage
void getDepthImage(xn::DepthMetaData& depthMD, cv::Mat& depth_image)
{
int rows = depthMD.GetUnderlying()->pMap->Res.Y;
int cols = depthMD.GetUnderlying()->pMap->Res.X;
// Data is 16-bit unsigned depths in mm
cv::Mat tempmat(rows, cols, CV_16U);
tempmat.data = (uchar*) depthMD.GetUnderlying()->pData;
// Convert to floating point meters
tempmat.convertTo(depth_image, CV_32F);
depth_image /= 1000;
}
示例4: grab
virtual bool grab( xn::DepthMetaData& depthMetaData,
xn::ImageMetaData& imageMetaData )
{
while(1)
{
if( !isDepthFilled )
isDepthFilled = popDepthMetaData(depth);
if( !isImageFilled )
isImageFilled = popImageMetaData(image);
if( !isDepthFilled || !isImageFilled )
break;
double timeDiff = 1e-3 * std::abs(static_cast<double>(depth.Timestamp()) - static_cast<double>(image.Timestamp()));
if( timeDiff <= approxSyncGrabber.maxTimeDuration )
{
depthMetaData.InitFrom(depth);
imageMetaData.InitFrom(image);
isDepthFilled = isImageFilled = false;
return true;
}
else
{
if( depth.Timestamp() < image.Timestamp() )
isDepthFilled = false;
else
isImageFilled = false;
}
}
return false;
}
示例5: popDepthMetaData
virtual inline bool popDepthMetaData( xn::DepthMetaData& depthMetaData )
{
cv::Ptr<xn::DepthMetaData> depthPtr;
bool isPop = depthQueue.try_pop(depthPtr);
if( isPop )
depthMetaData.CopyFrom(*depthPtr);
return isPop;
}
示例6: getDepthMapFromMetaData
inline void getDepthMapFromMetaData( const xn::DepthMetaData& depthMetaData, cv::Mat& depthMap, XnUInt64 noSampleValue, XnUInt64 shadowValue )
{
int cols = depthMetaData.XRes();
int rows = depthMetaData.YRes();
depthMap.create( rows, cols, CV_16UC1 );
const XnDepthPixel* pDepthMap = depthMetaData.Data();
// CV_Assert( sizeof(unsigned short) == sizeof(XnDepthPixel) );
memcpy( depthMap.data, pDepthMap, cols*rows*sizeof(XnDepthPixel) );
cv::Mat badMask = (depthMap == (double)noSampleValue) | (depthMap == (double)shadowValue) | (depthMap == 0);
// mask the pixels with invalid depth
depthMap.setTo( cv::Scalar::all( CvCapture_OpenNI::INVALID_PIXEL_VAL ), badMask );
}
示例7: get_depth_meta_data
/**
* @brief Gets a copy of the Color cv::Mat.
* @details Gets a copy of the Color cv::Mat, if the Image Generator
* (_image_generator) is active.
*
* @param[out] depth
* Copy of the Image cv::Mat.
*
* @retval true if the cv::Mat was successfully copied.
* @retval false if the generator is not active or some other error occurred.
*/
bool NIKinect::get_depth_meta_data(xn::DepthMetaData& depth){
if(this->_flags[NIKinect::DEPTH_G]){
depth.CopyFrom(this->_depth_md);
return true;
}
else{
return false;
}
}
示例8: initTexs
//- - - - - - - - - - - - - - - - - -
//
void C_TrackWindow::initTexs( const xn::DepthMetaData& depthMD ) {
struct getClosestPowerOfTwo {
inline unsigned int operator()( unsigned int n) {
unsigned int m = 2;
while(m < n) m<<=1;
return m;
};
};
GLuint texID = 0;
glGenTextures( 1, &depthTexID_ );
texWidth_ = getClosestPowerOfTwo()( depthMD.XRes() );
texHeight_ = getClosestPowerOfTwo()( depthMD.YRes() );
pDepthTexBuf_ = new unsigned char[ texWidth_ * texHeight_ * 4 ];
glBindTexture( GL_TEXTURE_2D, depthTexID_ );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
示例9: setDepthHistgram
//----------------------------------------------------
// ヒストグラム作成関数
//----------------------------------------------------
void setDepthHistgram(const xn::DepthGenerator& depth, const xn::DepthMetaData& depthMD, float _pDepthHist[]){
xnOSMemSet(_pDepthHist, 0, KINECT_MAX_DEPTH * sizeof(float)); // g_pDepthHistの全てに0を代入
unsigned int points = 0;
const XnDepthPixel* pDepth = depthMD.Data();
for (XnUInt y = 0; y < KINECT_IMAGE_HEIGHT; ++ y) {
for (XnUInt x = 0; x < KINECT_IMAGE_WIDTH; ++ x, ++ pDepth) {
if (*pDepth != 0) {
_pDepthHist[*pDepth] ++;
points ++;
}
}
}
for (int i = 1; i < KINECT_MAX_DEPTH; ++ i) {
_pDepthHist[i] += _pDepthHist[i - 1];
}
if ( points != 0) {
for (int i = 1; i < KINECT_MAX_DEPTH; ++ i) {
_pDepthHist[i] = (unsigned int)(256 * (1.0f - (_pDepthHist[i] / points)));
}
}
}
示例10: DrawDepthMap
void DrawDepthMap(const xn::DepthMetaData& dm)
{
static bool bInitialized = false;
static GLuint depthTexID;
static unsigned char* pDepthTexBuf;
static int texWidth, texHeight;
float topLeftX;
float topLeftY;
float bottomRightY;
float bottomRightX;
float texXpos;
float texYpos;
if(!bInitialized)
{
XnUInt16 nXRes = dm.XRes();
XnUInt16 nYRes = dm.YRes();
texWidth = getClosestPowerOfTwo(nXRes);
texHeight = getClosestPowerOfTwo(nYRes);
depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ;
bInitialized = true;
topLeftX = nXRes;
topLeftY = 0;
bottomRightY = nYRes;
bottomRightX = 0;
texXpos =(float)nXRes/texWidth;
texYpos =(float)nYRes/texHeight;
memset(texcoords, 0, 8*sizeof(float));
texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos;
}
unsigned int nValue = 0;
unsigned int nHistValue = 0;
unsigned int nIndex = 0;
unsigned int nX = 0;
unsigned int nY = 0;
unsigned int nNumberOfPoints = 0;
XnUInt16 g_nXRes = dm.XRes();
XnUInt16 g_nYRes = dm.YRes();
unsigned char* pDestImage = pDepthTexBuf;
const XnUInt16* pDepth = dm.Data();
// Calculate the accumulative histogram
memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float));
for (nY=0; nY<g_nYRes; nY++)
{
for (nX=0; nX<g_nXRes; nX++)
{
nValue = *pDepth;
if (nValue != 0)
{
g_pDepthHist[nValue]++;
nNumberOfPoints++;
}
pDepth++;
}
}
for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
{
g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1];
}
if (nNumberOfPoints)
{
for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
{
g_pDepthHist[nIndex] = (unsigned int)(256 * (1.0f - (g_pDepthHist[nIndex] / nNumberOfPoints)));
}
}
pDepth = dm.Data();
{
XnUInt32 nIndex = 0;
// Prepare the texture map
for (nY=0; nY<g_nYRes; nY++)
{
for (nX=0; nX < g_nXRes; nX++, nIndex++)
{
nValue = *pDepth;
if (nValue != 0)
{
nHistValue = g_pDepthHist[nValue];
pDestImage[0] = nHistValue;
pDestImage[1] = nHistValue;
pDestImage[2] = nHistValue;
}
else
{
pDestImage[0] = 0;
//.........这里部分代码省略.........
示例11: DrawDepthMap
void DrawDepthMap(const xn::DepthMetaData& dmd, const xn::SceneMetaData& smd)
{
static bool bInitialized = false;
static GLuint depthTexID;
static unsigned char* pDepthTexBuf;
static int texWidth, texHeight;
float topLeftX;
float topLeftY;
float bottomRightY;
float bottomRightX;
float texXpos;
float texYpos;
if(!bInitialized)
{
texWidth = getClosestPowerOfTwo(dmd.XRes());
texHeight = getClosestPowerOfTwo(dmd.YRes());
// printf("Initializing depth texture: width = %d, height = %d\n", texWidth, texHeight);
depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ;
// printf("Initialized depth texture: width = %d, height = %d\n", texWidth, texHeight);
bInitialized = true;
topLeftX = dmd.XRes();
topLeftY = 0;
bottomRightY = dmd.YRes();
bottomRightX = 0;
texXpos =(float)dmd.XRes()/texWidth;
texYpos =(float)dmd.YRes()/texHeight;
memset(texcoords, 0, 8*sizeof(float));
texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos;
}
unsigned int nValue = 0;
unsigned int nHistValue = 0;
unsigned int nIndex = 0;
unsigned int nX = 0;
unsigned int nY = 0;
unsigned int nNumberOfPoints = 0;
XnUInt16 g_nXRes = dmd.XRes();
XnUInt16 g_nYRes = dmd.YRes();
unsigned char* pDestImage = pDepthTexBuf;
const XnDepthPixel* pDepth = dmd.Data();
const XnLabel* pLabels = smd.Data();
// Calculate the accumulative histogram
memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float));
for (nY=0; nY<g_nYRes; nY++)
{
for (nX=0; nX<g_nXRes; nX++)
{
nValue = *pDepth;
if (nValue != 0)
{
g_pDepthHist[nValue]++;
nNumberOfPoints++;
}
pDepth++;
}
}
for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
{
g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1];
}
if (nNumberOfPoints)
{
for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
{
g_pDepthHist[nIndex] = (unsigned int)(256 * (1.0f - (g_pDepthHist[nIndex] / nNumberOfPoints)));
}
}
pDepth = dmd.Data();
if (g_bDrawPixels)
{
XnUInt32 nIndex = 0;
// Prepare the texture map
for (nY=0; nY<g_nYRes; nY++)
{
for (nX=0; nX < g_nXRes; nX++, nIndex++)
{
pDestImage[0] = 0;
pDestImage[1] = 0;
pDestImage[2] = 0;
if (g_bDrawBackground || *pLabels != 0)
{
nValue = *pDepth;
XnLabel label = *pLabels;
XnUInt32 nColorID = label % nColors;
if (label == 0)
{
//.........这里部分代码省略.........
示例12: retrievePointCloudMap
IplImage* CvCapture_OpenNI::retrievePointCloudMap()
{
if( !depthMetaData.Data() )
return 0;
cv::Mat depth;
getDepthMapFromMetaData( depthMetaData, depth, noSampleValue, shadowValue );
const int badPoint = INVALID_PIXEL_VAL;
const float badCoord = INVALID_COORDINATE_VAL;
int cols = depthMetaData.XRes(), rows = depthMetaData.YRes();
cv::Mat pointCloud_XYZ( rows, cols, CV_32FC3, cv::Scalar::all(badPoint) );
cv::Ptr<XnPoint3D> proj = new XnPoint3D[cols*rows];
cv::Ptr<XnPoint3D> real = new XnPoint3D[cols*rows];
for( int y = 0; y < rows; y++ )
{
for( int x = 0; x < cols; x++ )
{
int ind = y*cols+x;
proj[ind].X = (float)x;
proj[ind].Y = (float)y;
proj[ind].Z = depth.at<unsigned short>(y, x);
}
}
depthGenerator.ConvertProjectiveToRealWorld(cols*rows, proj, real);
for( int y = 0; y < rows; y++ )
{
for( int x = 0; x < cols; x++ )
{
// Check for invalid measurements
if( depth.at<unsigned short>(y, x) == badPoint ) // not valid
pointCloud_XYZ.at<cv::Point3f>(y,x) = cv::Point3f( badCoord, badCoord, badCoord );
else
{
int ind = y*cols+x;
pointCloud_XYZ.at<cv::Point3f>(y,x) = cv::Point3f( real[ind].X*0.001f, real[ind].Y*0.001f, real[ind].Z*0.001f); // from mm to meters
}
}
}
outputMaps[CV_CAP_OPENNI_POINT_CLOUD_MAP].mat = pointCloud_XYZ;
return outputMaps[CV_CAP_OPENNI_POINT_CLOUD_MAP].getIplImagePtr();
}
示例13: retrieveDepthMap
IplImage* CvCapture_OpenNI::retrieveDepthMap()
{
if( !depthMetaData.Data() )
return 0;
getDepthMapFromMetaData( depthMetaData, outputMaps[CV_CAP_OPENNI_DEPTH_MAP].mat, noSampleValue, shadowValue );
return outputMaps[CV_CAP_OPENNI_DEPTH_MAP].getIplImagePtr();
}
示例14:
IplImage* CvCapture_OpenNI::retrieveDisparityMap_32F()
{
if( !depthMetaData.Data() )
return 0;
computeDisparity_32F( depthMetaData, outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].mat, baseline, depthFocalLength_VGA, noSampleValue, shadowValue );
return outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].getIplImagePtr();
}
示例15: getDepthMap
std::string getDepthMap(bool br) {
{
ReadLock r_lock(myLock);
stringstream emitter;
emitter << "{DepthMap," << g_depthMD.XRes() << ","<< g_depthMD.YRes() << "}[";
if(g_depthMD.XRes() != 0){
for(int i = 0; i < g_depthMD.XRes(); i++) {
if(i>0 && br == true) emitter << "<BR>";
for(int j = 0; j < g_depthMD.YRes(); j++) {
emitter << g_depthMD(i, j);
emitter << ",";
}
}
}
emitter << "]";
return emitter.str();
}
}