private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame) { if (sensorData == null || sensorData.bodyIndexImage == null) { return(false); } CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1); System.IntPtr rawPtrAlpha; cvAlphaMap.GetRawData(out rawPtrAlpha); if (sensorData.selectedBodyIndex != 255) { // copy body-index selectively byte btSelBI = sensorData.selectedBodyIndex; int iBodyIndexLength = sensorData.bodyIndexImage.Length; for (int i = 0; i < iBodyIndexLength; i++) { byte btBufBI = sensorData.bodyIndexImage[i]; if (btBufBI == btSelBI) { cvAlphaMap.Set1D(i, btBufBI); } else { cvAlphaMap.Set1D(i, 255); } } } else { // copy the entire body-index buffer Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length); } // make the image b&w cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv); // apply erode, dilate and blur cvAlphaMap.Erode(cvAlphaMap); cvAlphaMap.Dilate(cvAlphaMap); cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5); //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7); // get the foreground image Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length); return(true); }
private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame) { if (sensorData == null || sensorData.bodyIndexImage == null) { return(false); } CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1); System.IntPtr rawPtrAlpha; cvAlphaMap.GetRawData(out rawPtrAlpha); Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length); cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv); //cvAlphaMap.Erode(cvAlphaMap); cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 10, 10); cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7); //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5); Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length); return(true); }
private static bool GetForegroundAlphaFrame(SensorData sensorData, bool bLimitedUsers, ICollection<int> alTrackedIndexes, ref byte[] fgAlphaFrame) { if (sensorData == null || sensorData.bodyIndexImage == null) return false; CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1); System.IntPtr rawPtrAlpha; cvAlphaMap.GetRawData(out rawPtrAlpha); if (sensorData.selectedBodyIndex != 255 || bLimitedUsers) { // copy body-index selectively byte btSelBI = sensorData.selectedBodyIndex; int iBodyIndexLength = sensorData.bodyIndexImage.Length; for (int i = 0; i < iBodyIndexLength; i++) { byte btBufBI = sensorData.bodyIndexImage[i]; bool bUserTracked = btSelBI != 255 ? btSelBI == btBufBI : (btBufBI != 255 ? alTrackedIndexes.Contains((int)btBufBI) : false); if (bUserTracked) { cvAlphaMap.Set1D(i, btBufBI); } else { cvAlphaMap.Set1D(i, 255); } } } else { // copy the entire body-index buffer Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length); } // make the image b&w cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv); // apply erode, dilate and blur cvAlphaMap.Erode(cvAlphaMap); cvAlphaMap.Dilate(cvAlphaMap); cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5); //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7); // get the foreground image Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length); return true; }
private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame) { if(sensorData == null || sensorData.bodyIndexImage == null) return false; CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1); System.IntPtr rawPtrAlpha; cvAlphaMap.GetRawData(out rawPtrAlpha); Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length); cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv); cvAlphaMap.Erode(cvAlphaMap); cvAlphaMap.Dilate(cvAlphaMap); cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5); //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7); Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length); return true; }