32 #include "generator/Depth.h" 33 #include "generator/User.h" 34 #include "DeviceManager.h" 46 mParentDevice = pDevice;
58 boost::mutex::scoped_lock l(mmutex);
81 bool Depth::UpdateData(openni::VideoFrameRef frame)
83 boost::mutex::scoped_lock l(mmutex);
91 width = frame.getVideoMode().getResolutionX();
92 height = frame.getVideoMode().getResolutionY();
94 unsigned int dataSize = width * height *
sizeof(openni::DepthPixel);
95 unsigned int historySize = MAX_DEPTH *
sizeof(float);
97 mData = (
unsigned short*)malloc(dataSize);
98 memset(mData, 0, dataSize);
100 mCuttedData = (
unsigned short*)malloc(dataSize);
101 memset(mCuttedData, 0, dataSize);
103 mReadData = (
unsigned short*)malloc(dataSize);
104 memset(mReadData, 0, dataSize);
106 mDepthHist = (
float*)malloc(historySize);
107 memset(mDepthHist, 0, historySize);
109 mReadDepthHist = (
float*)malloc(historySize);
110 memset(mReadDepthHist, 0, historySize);
118 memcpy(mData, frame.getData(), width * height *
sizeof(openni::DepthPixel));
119 memcpy(mCuttedData, frame.getData(), width * height *
sizeof(openni::DepthPixel));
122 const openni::DepthPixel* pDepth = mData;
125 memset(mDepthHist, 0, MAX_DEPTH *
sizeof(
float));
127 unsigned int nNumberOfPoints = 0;
128 for (
int y = 0; y < frame.getHeight(); ++y)
130 for (
int x = 0; x < frame.getWidth(); ++x, ++pDepth)
134 mDepthHist[*pDepth]++;
139 for (
int nIndex = 1; nIndex < MAX_DEPTH; nIndex++)
141 mDepthHist[nIndex] += mDepthHist[nIndex-1];
145 for (
int nIndex=1; nIndex < MAX_DEPTH; nIndex++)
147 mDepthHist[nIndex] = 256.0f * (1.0f - (mDepthHist[nIndex] / nNumberOfPoints));
153 const unsigned short* Depth::GetBuffer()
158 const unsigned short* Depth::GetCuttedBuffer()
163 void Depth::GetBuffer(PtrObjBitmap B)
167 boost::mutex::scoped_lock l(mmutex);
168 if (mData && mDepthHist && mReadData && mReadDepthHist)
170 memcpy(mReadData, mData, width * height *
sizeof(openni::DepthPixel));
171 memcpy(mReadDepthHist, mDepthHist, MAX_DEPTH *
sizeof(
float));
178 if ((B->TailleW != width) || (B->TailleH != height))
187 unsigned int destByte = 0;
189 const openni::DepthPixel* pDepth = mReadData;
190 for (y=0; y<height; y++)
192 const openni::DepthPixel* pDepthRow = pDepth;
193 for (x=0; x<width; x++, ++pDepthRow)
197 color = (int)mReadDepthHist[*pDepthRow];
199 destByte = (x + y * width) * 3;
201 B->bits[destByte] = color;
202 B->bits[destByte+1] = color;
203 B->bits[destByte+2] = color;
210 bool Depth::IsValid()
212 return mData != 0 ? true :
false;
215 void Depth::SetMirror(
bool state)
223 void Depth::GetDepthSize(
int &w,
int &h)
229 void Depth::SetDistCutoff(
int dist)
234 int Depth::GetDistCutoff()
239 void Depth::SetAngCutoff(
float ang)
244 float Depth::GetAngCutoff()
249 void Depth::DepthCutoff()
251 openni::DepthPixel val2Replace = 0;
255 if ((fAngCutoff > 0.0f) && (fAngCutoff < 57.7f))
256 xcut = (int)(((
float)width / 57.8f) * fAngCutoff);
258 int minxcut = (width / 2) - (xcut / 2);
259 int maxxcut = (width / 2) + (xcut / 2);
260 for(
int y(0); y < height; ++y)
262 for(
int x(0); x < width; ++x)
266 if((x < minxcut) || (x > maxxcut) || (iDistCutoff < mCuttedData[pos]))
267 mCuttedData[pos] = val2Replace;
Kinect device handling. .