// Update is called once per frame void Update() { MatDisplay.SetCameraFoV(41.5f); Image cameraImage = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); if (cameraImage == null) { return; } if (_cameraImageMat == null) { //First frame -> generate Mat with same dimensions as camera feed _cameraImageMat = new Mat(cameraImage.Height, cameraImage.Width, CvType.CV_8UC4); } _cameraImageMat.put(0, 0, cameraImage.Pixels); // transferring image data to Mat if (FingerPointTarget.GetComponent <ImageTargetBehaviour>().CurrentStatus != TrackableBehaviour.Status.TRACKED) { MatDisplay.DisplayMat(_cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); return; } FindHomographyPoints(out var matDst, out var matObj); var H = Calib3d.findHomography(matObj, matDst); try { var bWMat = GetBWSkinColor(); var fingerTipCoor = FindFingerTip(bWMat); var fingerPointInWorldSpace = FingerPointInWorldSpace(fingerTipCoor); FingerPlane.position = fingerPointInWorldSpace; var colorPixelValue = FindPixelValue(_cameraImageMat, Color.position); var drawPixelValue = FindPixelValue(bWMat, Draw.position); if ((int)drawPixelValue.First() == 255) { //Debug.Log($"{colorPixelValue[0]}, {colorPixelValue[1]}, {colorPixelValue[2]}"); //Debug.Log("Found Draw"); //draw at finger pos var camMask = PaintCircle(fingerTipCoor); DrawMaskOnCanvas(camMask, H, colorPixelValue); } } catch { } var blendTex = BlendMats(H, _cameraImageMat, _drawingPlaceMat); MatDisplay.DisplayMat(blendTex, MatDisplaySettings.FULL_BACKGROUND); }
// Update is called once per frame void Update() { MatDisplay.SetCameraFoV(41.5f); Image cameraImage = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); if (cameraImage != null) { if (cameraImageMat == null) { cameraImageMat = new Mat(cameraImage.Height, cameraImage.Width, CvType.CV_8UC4); } cameraImageMat.put(0, 0, cameraImage.Pixels); MatDisplay.DisplayMat(cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); // Imgproc.blur(cameraImageMat, cameraImageMatBlur, new Size (16,16)); // MatDisplay.DisplayMat (cameraImageMatBlur, MatDisplaySettings.BOTTOM_LEFT ); } }
// Update is called once per frame void Update() { MatDisplay.SetCameraFoV(41.5f); Image cameraImageRaw = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); if (cameraImageRaw != null) { if (cameraImageMat == null) { // Rows first, then columns. cameraImageMat = new Mat(cameraImageRaw.Height, cameraImageRaw.Width, CvType.CV_8UC4); grayScale = new Mat(cameraImageRaw.Height, cameraImageRaw.Width, CvType.CV_8UC4); } byte[] pixels = cameraImageRaw.Pixels; cameraImageMat.put(0, 0, pixels); Imgproc.cvtColor(cameraImageMat, grayScale, Imgproc.COLOR_RGB2GRAY); MatDisplay.DisplayMat(grayScale, MatDisplaySettings.FULL_BACKGROUND); } }
// Update is called once per frame void Update() { MatDisplay.SetCameraFoV(41.5f); Image cameraImageRaw = CameraDevice.Instance.GetCameraImage( Image.PIXEL_FORMAT.RGBA8888); if (cameraImageRaw != null) { if (cameraImageMat == null) { // Rows first, then columns. cameraImageMat = new Mat(cameraImageRaw.Height, cameraImageRaw.Width, CvType.CV_8UC4); countourMat = new Mat(cameraImageRaw.Height, cameraImageRaw.Width, CvType.CV_8UC4); } byte[] pixels = cameraImageRaw.Pixels; cameraImageMat.put(0, 0, pixels); Imgproc.cvtColor(cameraImageMat, countourMat, Imgproc.COLOR_RGB2GRAY); Imgproc.adaptiveThreshold(countourMat, countourMat, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 7, 7); MatDisplay.DisplayMat(countourMat, MatDisplaySettings.FULL_BACKGROUND); } }
// Update is called once per frame void Update() { MatDisplay.SetCameraFoV(41.5f); Image cameraImage = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); if (cameraImage == null) { return; } if (_cameraImageMat == null) { //First frame -> generate Mat with same dimensions as camera feed _cameraImageMat = new Mat(cameraImage.Height, cameraImage.Width, CvType.CV_8UC4); } _cameraImageMat.put(0, 0, cameraImage.Pixels); // transferring image data to Mat if (AlphabetTarget.GetComponent <ImageTargetBehaviour>().CurrentStatus != TrackableBehaviour.Status.TRACKED) { MatDisplay.DisplayMat(_cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); return; } var fingerColorMat = FindFingerColor(); var test = Send.position; test.y = -test.y; var screenPosSend = Camera.WorldToScreenPoint(test); var value = fingerColorMat.get((int)screenPosSend.y, (int)screenPosSend.x); //Debug.Log($"Circle: {screenPosSend}"); //Debug.Log($"backspace: {Camera.WorldToScreenPoint(KeyboardPos[27].position)}"); //Debug.Log($"backspace: {Camera.WorldToScreenPoint(KeyboardPos[20].position)}"); //Debug.Log($"{value[0]}"); // Check if value at finger is white (which means that finger is present) try { var fingerPointInWorldSpace = FingerPointInWorldSpace(fingerColorMat); FingerPlane.position = fingerPointInWorldSpace; if ((int)value[0] > 250 && !_keyPressed) { StartCoroutine(DelayTyping()); var oldDistance = float.MaxValue; var letter = string.Empty; var maxDistance = Vector3.Distance(Camera.WorldToScreenPoint(KeyboardPos[0].position), Camera.WorldToScreenPoint(KeyboardPos[7].position)); KeyboardPos.ForEach(x => { var worldToScreenPoint = Camera.WorldToScreenPoint(x.position); var distance = Vector3.Distance(Camera.WorldToScreenPoint(fingerPointInWorldSpace), worldToScreenPoint); if (distance > oldDistance || distance > maxDistance) { return; } letter = x.name; oldDistance = distance; }); Debug.Log(letter); switch (letter) { case "BackSpace": Text.text = Text.text.Remove(Text.text.Length - 1); break; case "Space": Text.text += " "; break; default: Text.text += letter; break; } } } catch { } MatDisplay.DisplayMat(_cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); }