| 166 | |
| 167 | |
| 168 | void UserTracker::CalcHistogram(const XnDepthPixel* pDepth, XnUInt16 xRes,XnUInt16 yRes) |
| 169 | { |
| 170 | XnDepthPixel zRes = m_DepthGenerator.GetDeviceMaxDepth() + 1; |
| 171 | if(s_pDepthHist==NULL) |
| 172 | s_pDepthHist=XN_NEW_ARR(float,zRes); // initialize the histogram's buffer |
| 173 | |
| 174 | |
| 175 | XnUInt32 nNumberOfPoints = 0; // will hold the number of points in the histogram |
| 176 | XnDepthPixel nValue; // will hold temporary pixel values. |
| 177 | |
| 178 | xnOSMemSet(s_pDepthHist, 0, zRes*sizeof(float)); // clear everything, we start from scratch |
| 179 | |
| 180 | // calculate the basic histogram (i.e. the buffer in position X will hold the number of pixels |
| 181 | // in the depth map which have a value of X. |
| 182 | // NOTE: a value of 0 is not counted (i.e. m_pDepthHist[0] will always be 0) and we assume |
| 183 | // MAX_DEPTH is large enough so that we never have a value larger than it. |
| 184 | for (XnUInt16 nY=0; nY<yRes; nY++) |
| 185 | { |
| 186 | for (XnUInt16 nX=0; nX<xRes; nX++) |
| 187 | { |
| 188 | nValue = *pDepth; |
| 189 | |
| 190 | if (nValue != 0) |
| 191 | { |
| 192 | s_pDepthHist[nValue]++; |
| 193 | nNumberOfPoints++; |
| 194 | } |
| 195 | pDepth++; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if(nNumberOfPoints==0) |
| 200 | return; // nothing to do, there are no values. |
| 201 | // turn the histogram to a cumulative histogram |
| 202 | for (XnUInt16 nIndex=1; nIndex<zRes; nIndex++) |
| 203 | { |
| 204 | s_pDepthHist[nIndex] += s_pDepthHist[nIndex-1]; |
| 205 | } |
| 206 | // normalize the values to a value between 0 and 256. This is the color we want to see elements |
| 207 | // of this value as (multiplier). |
| 208 | |
| 209 | for (XnUInt16 nIndex=1; nIndex<zRes; nIndex++) |
| 210 | { |
| 211 | s_pDepthHist[nIndex] = (256 * (1.0f - (s_pDepthHist[nIndex] / nNumberOfPoints))); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | void UserTracker::FillTexture(unsigned char* pTexBuf, XnUInt16 nTexWidth, XnUInt16 /*nTexHeight*/, XnBool bDrawBackground) |
| 216 | { |
nothing calls this directly
no test coverage detected