Created
April 17, 2021 21:53
-
-
Save deivid-01/b2350206421d94ec85ca8810ef0a11a1 to your computer and use it in GitHub Desktop.
Cuenta con funciones para obtener la camara, coroutinas para dilatar y erocionar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| using OpenCvSharp; | |
| public class OpenCvTools : MonoBehaviour | |
| { | |
| public static RawImage rawImage; | |
| #region Singlenton | |
| public static OpenCvTools instance; | |
| private void Awake() | |
| { | |
| instance = this; | |
| } | |
| public static void SetCameraTexture(ref WebCamTexture webCamTexture) | |
| { | |
| WebCamDevice[] devices = WebCamTexture.devices; | |
| webCamTexture = new WebCamTexture(devices[0].name); | |
| webCamTexture.Play(); | |
| } | |
| #endregion | |
| public IEnumerator Dilate(Mat mat, Mat strElem, int numDilations, int actual = 0) | |
| { | |
| yield return new WaitForSeconds(0.1f); | |
| Cv2.Dilate(mat, mat, strElem, iterations: 1); | |
| rawImage.texture = OpenCvSharp.Unity.MatToTexture(mat); | |
| if (actual < numDilations) | |
| { | |
| StartCoroutine(Dilate(mat, strElem, numDilations, actual + 1)); | |
| } | |
| } | |
| public IEnumerator Erode(Mat mat, Mat strElem, int numDilations, int actual = 0) | |
| { | |
| yield return new WaitForSeconds(0.1f); | |
| Cv2.Erode(mat, mat, strElem, iterations: 1); | |
| rawImage.texture = OpenCvSharp.Unity.MatToTexture(mat); | |
| if (actual < numDilations) | |
| { | |
| StartCoroutine(Erode(mat, strElem, numDilations, actual + 1)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment