private void ProcessFrame(object sender, EventArgs e) { var mat = new Mat(); this.webcam.Read(mat); CudaImage <Bgr, Byte> gpuImg = new CudaImage <Bgr, byte>(); gpuImg.Upload(mat); CudaImage <Gray, Byte> grayImg = gpuImg.Convert <Gray, Byte>(); GpuMat region = new GpuMat(); haarCascade.DetectMultiScale(grayImg, region); Rectangle[] faceRegion = haarCascade.Convert(region); Rectangle face; if (faceRegion.Length > 0 && faceRegion[0].Width > 0) { if (!IsRegionValid(faceRegion[0])) { return; } face = faceRegion[0]; float meterPerPxl = (userFaceSize / face.Width) / 100f; this._userPosition.x = -(face.X + (face.Width / 2) - (camWidth / 2)) * ((userFaceSize / face.Width) / 100); this._userPosition.y = -(face.Y + (face.Height / 2) - (camHeight / 2)) * ((userFaceSize / face.Width) / 100); this._userPosition.z = -camDistanceRatio * ((userFaceSize / face.Width) / 100); currentFace = face; this.newFaceDetected = true; } else { currentFace.Width = -1; } /*if (webcamFeedbackEnabled) { * var img = mat.ToImage<Bgr, byte>(); * for (int i = 0; i < faceRegion.Length; i++) { * if (i == 0) * img.Draw(face, new Bgr(255, 255, 0), 4); * else * img.Draw(faceRegion[i], new Bgr(0, 255, 255), 4); * } * * Dispatcher.InvokeAsync(() => { * Debug.Log(img.Convert<Rgb, byte>().Bytes.Length); * currentFrame.LoadRawTextureData(img.Convert<Rgb, byte>().Bytes); * currentFrame.Apply(); * img.Dispose(); * }); * }*/ }