MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / ReaderThread

Method ReaderThread

Samples/UserTracker.net/MainWindow.cs:291–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

289 }
290
291 private unsafe void ReaderThread()
292 {
293 DepthMetaData depthMD = new DepthMetaData();
294
295 while (this.shouldRun)
296 {
297 try
298 {
299 this.context.WaitOneUpdateAll(this.depth);
300 }
301 catch (Exception)
302 {
303 }
304
305 this.depth.GetMetaData(depthMD);
306
307 CalcHist(depthMD);
308
309 lock (this)
310 {
311 Rectangle rect = new Rectangle(0, 0, this.bitmap.Width, this.bitmap.Height);
312 BitmapData data = this.bitmap.LockBits(rect, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
313
314
315 if (this.shouldDrawPixels)
316 {
317 ushort* pDepth = (ushort*)this.depth.DepthMapPtr.ToPointer();
318 ushort* pLabels = (ushort*)this.userGenerator.GetUserPixels(0).LabelMapPtr.ToPointer();
319
320 // set pixels
321 for (int y = 0; y < depthMD.YRes; ++y)
322 {
323 byte* pDest = (byte*)data.Scan0.ToPointer() + y * data.Stride;
324 for (int x = 0; x < depthMD.XRes; ++x, ++pDepth, ++pLabels, pDest += 3)
325 {
326 pDest[0] = pDest[1] = pDest[2] = 0;
327
328 ushort label = *pLabels;
329 if (this.shouldDrawBackground || *pLabels != 0)
330 {
331 Color labelColor = Color.White;
332 if (label != 0)
333 {
334 labelColor = colors[label % ncolors];
335 }
336
337 byte pixel = (byte)this.histogram[*pDepth];
338 pDest[0] = (byte)(pixel * (labelColor.B / 256.0));
339 pDest[1] = (byte)(pixel * (labelColor.G / 256.0));
340 pDest[2] = (byte)(pixel * (labelColor.R / 256.0));
341 }
342 }
343 }
344 }
345 this.bitmap.UnlockBits(data);
346
347 Graphics g = Graphics.FromImage(this.bitmap);
348 int[] users = this.userGenerator.GetUsers();

Callers

nothing calls this directly

Calls 9

WaitOneUpdateAllMethod · 0.80
IsTrackingMethod · 0.80
IsCalibratingMethod · 0.80
GetMetaDataMethod · 0.45
GetUserPixelsMethod · 0.45
GetUsersMethod · 0.45
GetCoMMethod · 0.45
DisposeMethod · 0.45

Tested by

no test coverage detected