PlotExample.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using System.Collections;
  4. using OpenCVForUnity.CoreModule;
  5. using OpenCVForUnity.PlotModule;
  6. using OpenCVForUnity.ImgprocModule;
  7. using OpenCVForUnity.UnityUtils;
  8. namespace OpenCVForUnityExample
  9. {
  10. /// <summary>
  11. /// Plot Example
  12. /// An examples of creating 2D plot using the plot (Plot function for Mat data) module.
  13. /// </summary>
  14. public class PlotExample : MonoBehaviour
  15. {
  16. // Use this for initialization
  17. void Start ()
  18. {
  19. // Plot data must be a 1xN or Nx1 matrix.
  20. // Plot data type must be double (CV_64F)
  21. Mat data = new Mat (30, 1, CvType.CV_64F);
  22. Core.randu (data, 0, 500); // random values
  23. Mat plot_result = new Mat ();
  24. // Plot2d plot = Plot.createPlot2d (data);
  25. Plot2d plot = Plot2d.create (data);
  26. plot.setPlotBackgroundColor (new Scalar (50, 50, 50));
  27. plot.setPlotLineColor (new Scalar (50, 50, 255));
  28. plot.render (plot_result);
  29. Imgproc.cvtColor (plot_result, plot_result, Imgproc.COLOR_BGR2RGB);
  30. Texture2D texture = new Texture2D (plot_result.cols (), plot_result.rows (), TextureFormat.RGBA32, false);
  31. Utils.matToTexture2D (plot_result, texture);
  32. gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
  33. }
  34. // Update is called once per frame
  35. void Update ()
  36. {
  37. }
  38. /// <summary>
  39. /// Raises the back button click event.
  40. /// </summary>
  41. public void OnBackButtonClick ()
  42. {
  43. SceneManager.LoadScene ("OpenCVForUnityExample");
  44. }
  45. }
  46. }