void Update() { if (reader != null) { ColorFrame frame = reader.AcquireLatestFrame(); if (frame != null) { frame.CopyConvertedFrameDataToArray(data, ColorImageFormat.Rgba); frame.Dispose(); frame = null; } } else { return; } MatUtils.copyToMat(data, rgbaMat); if (filterType == FilterTypePreset.NONE) { Imgproc.putText(rgbaMat, "Filter Type: NONE " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.SEPIA) { Core.transform(rgbaMat, rgbaMat, sepiaKernel); Imgproc.putText(rgbaMat, "Filter Type: SEPIA " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.PIXELIZE) { Imgproc.resize(rgbaMat, pixelizeIntermediateMat, pixelizeSize0, 0.1, 0.1, Imgproc.INTER_NEAREST); Imgproc.resize(pixelizeIntermediateMat, rgbaMat, rgbaMat.size(), 0.0, 0.0, Imgproc.INTER_NEAREST); Imgproc.putText(rgbaMat, "Filter Type: PIXELIZE " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.COMIC) { comicFilter.Process(rgbaMat, rgbaMat); Imgproc.putText(rgbaMat, "Filter Type: COMIC " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } Utils.matToTexture2D(rgbaMat, texture); }
void Update() { if (reader != null) { MultiSourceFrame frame = reader.AcquireLatestFrame(); if (frame != null) { using (ColorFrame colorFrame = frame.ColorFrameReference.AcquireFrame()) { if (colorFrame != null) { colorFrame.CopyConvertedFrameDataToArray(colorData, ColorImageFormat.Rgba); } } using (DepthFrame depthFrame = frame.DepthFrameReference.AcquireFrame()) { if (depthFrame != null) { //Debug.Log ("bodyIndexFrame not null"); depthFrame.CopyFrameDataToArray(depthData); } } using (BodyIndexFrame bodyIndexFrame = frame.BodyIndexFrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { //Debug.Log ("bodyIndexFrame not null"); bodyIndexFrame.CopyFrameDataToArray(bodyIndexData); } } frame = null; } } else { return; } MatUtils.copyToMat(colorData, outputMat); MatUtils.copyToMat(colorData, rgbaMat); // update mask image from bodyIndexData. coordinateMapper.MapColorFrameToDepthSpace(depthData, depthSpacePoints); for (int colorY = 0; colorY < colorFrameHeight; colorY++) { for (int colorX = 0; colorX < colorFrameWidth; colorX++) { int colorIndex = colorY * colorFrameWidth + colorX; int depthX = (int)(depthSpacePoints[colorIndex].X); int depthY = (int)(depthSpacePoints[colorIndex].Y); if ((0 <= depthX) && (depthX < depthFrameWidth) && (0 <= depthY) && (depthY < depthFrameHeight)) { int depthIndex = depthY * depthFrameWidth + depthX; if (bodyIndexData[depthIndex] == 255) { maskData[colorIndex] = 0; } else { maskData[colorIndex] = 255; } } } } MatUtils.copyToMat(maskData, maskMat); if (filterType == FilterTypePreset.NONE) { rgbaMat.copyTo(outputMat, maskMat); Imgproc.putText(outputMat, "Filter Type: NONE " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.SEPIA) { Core.transform(rgbaMat, rgbaMat, sepiaKernel); rgbaMat.copyTo(outputMat, maskMat); Imgproc.putText(outputMat, "Filter Type: SEPIA " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.PIXELIZE) { Imgproc.resize(rgbaMat, pixelizeIntermediateMat, pixelizeSize0, 0.1, 0.1, Imgproc.INTER_NEAREST); Imgproc.resize(pixelizeIntermediateMat, rgbaMat, rgbaMat.size(), 0.0, 0.0, Imgproc.INTER_NEAREST); rgbaMat.copyTo(outputMat, maskMat); Imgproc.putText(outputMat, "Filter Type: PIXELIZE " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } else if (filterType == FilterTypePreset.COMIC) { comicFilter.Process(rgbaMat, rgbaMat); rgbaMat.copyTo(outputMat, maskMat); Imgproc.putText(outputMat, "Filter Type: COMIC " + texture.width + "x" + texture.height, new Point(5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar(255, 0, 0, 255), 3); } Utils.matToTexture2D(outputMat, texture); }