Пример #1
0
        public void Process(BaseCameraApplication app)
        {
            CameraDataFilter filter = app.GetImageFilter();
            kernelCopyImage.Execute(new CLCalc.Program.MemoryObject[] {
                app.GetPrimaryDevice().GetDepthImage().GetMemoryObject(),
                filter.GetTextureImage(),
                filter.GetColorImage(),
                pointBuffer,
                colorBuffer}, new int[] { filter.GetDepthImage().Width, filter.GetDepthImage().Height });
            pointBuffer.ReadFromDeviceTo(points);
            int vertexCount = points.Length / 4;
            /*
            for (int i = 0; i < points.Length; i += 4)
            {

                float4 pt = new float4(points[i], points[i + 1], points[i + 2], points[i + 3]);
                if (pt.z>200.0&&pt.z < 2000.0f&&pt.w>100.0f)
                {
                    vertexCount++;
                }
            }
             * */
            colorBuffer.ReadFromDeviceTo(colors);
            string path = outputDir + "pointcloud" + counter.ToString("0000") + ".xyz";
            MeshReaderWriter writer = new MeshReaderWriter(vertexCount, 0, path);
            float minDepth = app.GetPrimaryDevice().GetMinDepth();
            float maxDepth = app.GetPrimaryDevice().GetMaxDepth();
            for (int i = 0; i < points.Length; i += 4)
            {
                float4 pt = new float4(points[i], points[i + 1], points[i + 2], points[i + 3]);
                float4 rgb = new float4(colors[i], colors[i + 1], colors[i + 2], colors[i + 3]);
                if (pt.z > minDepth && pt.z < maxDepth && pt.w > 100.0f)
                {
                    writer.AddPoint(pt, rgb);
                }
                else
                {
                    writer.AddPoint(new float4(), new float4());
                }
            }
            writer.Close();
            counter++;
        }
Пример #2
0
        public void Initialize(BaseCameraApplication capture)
        {
            DepthCameraFrame depthImage = capture.GetPrimaryDevice().GetDepthImage();
            this.width = depthImage.Width;
            this.height = depthImage.Height;
            this.filter = ((AdaptiveTemporalFilter)capture.GetImageFilter());
            CvSize sz = new CvSize(depthImage.Width, depthImage.Height);
            gray = new IplImage(sz, BitDepth.U8, 1);
            erode = new IplImage(sz, BitDepth.U8, 1);
            dilate = new IplImage(sz, BitDepth.U8, 1);
            tmp = new IplImage(sz, BitDepth.U8, 1);
            mask = new IplImage(sz, BitDepth.U8, 1);
            imgLabel = new IplImage(sz, BitDepth.F32, 1);
            faceDetectionBuffer = CLCalc.Program.Variable.Create(new ComputeBuffer<FaceLandmarks>(CLCalc.Program.Context, ComputeMemoryFlags.ReadWrite, 1));
            try
            {
                CLCalc.Program.Compile(capture.GetPrimaryDevice().GetPreprocessCode() + src);

            }
            catch (BuildProgramFailureComputeException ex)
            {
                System.Console.WriteLine(ex.Message);
                Environment.Exit(1);
            }
            irImageBuffer = CLCalc.Program.Variable.Create(new ComputeBuffer<byte>(CLCalc.Program.Context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, ir = new byte[width * height]));
            kernelCopyIRImage = new CLCalc.Program.Kernel("CopyIRImage");
            kernelFindFaceLandmarks = new CLCalc.Program.Kernel("FindFaceLandmarks");
        }
 public void Process(BaseCameraApplication app)
 {
     if (Visible || WireFrame)
     {
         DepthCameraFrame depthFrame = app.GetPrimaryDevice().GetDepthImage();
         ColorCameraFrame colorFrame = app.GetPrimaryDevice().GetColorImage();
         TextureMapFrame textureFrame = app.GetPrimaryDevice().GetTextureImage();
         CameraDataFilter filter = (CameraDataFilter)app.GetImageFilter();
         CLGLInteropFunctions.AcquireGLElements(new CLCalc.Program.MemoryObject[] { positionBuffer, colorBuffer, normalBuffer });
         CLCalc.Program.MemoryObject[] args = new CLCalc.Program.MemoryObject[] {
          app.GetPrimaryDevice().GetBoundingBox(),filter.GetDepthImage(),filter.GetTextureImage(),colorFrame.GetMemoryObject(),positionBuffer,colorBuffer,normalBuffer};
         kernelCopyImage.Execute(args, new int[] { depthFrame.Width, depthFrame.Height });
         CLGLInteropFunctions.ReleaseGLElements(new CLCalc.Program.MemoryObject[] { positionBuffer, colorBuffer, normalBuffer });
     }
 }