Advertisement
Guest User

OnVuforiaStarted

a guest
Nov 12th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. private void OnVuforiaStarted()
  2.         {
  3.             CameraDevice.Instance.SetFrameFormat(mPixelFormat, true);
  4.             CameraDevice.Instance.SetFocusMode(
  5.                 CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
  6.             //Vuforia.Image arCamera = CameraDevice.Instance.GetCameraImage(mPixelFormat);
  7.             imageVuforia = CameraDevice.Instance.GetCameraImage(mPixelFormat);
  8.            
  9.             Mat webCamTextureMat = matFromBytes(imageVuforia.Height, imageVuforia.Width, imageVuforia.Pixels, false, CvType.CV_8UC2);
  10.             texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);
  11.             gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
  12.            
  13.             gameObject.transform.localScale = new Vector3 (webCamTextureMat.cols (), webCamTextureMat.rows (), 1);
  14.  
  15.              if (fpsMonitor != null) {
  16.                 fpsMonitor.Add ("width", webCamTextureMat.width ().ToString ());
  17.                 fpsMonitor.Add ("height", webCamTextureMat.height ().ToString ());
  18.                 fpsMonitor.Add ("orientation", Screen.orientation.ToString ());
  19.                 fpsMonitor.consoleText = "Please touch the area of the open hand.";
  20.             }
  21.  
  22.  
  23.             float width = webCamTextureMat.width ();
  24.             float height = webCamTextureMat.height ();
  25.            
  26.             float widthScale = (float)Screen.width / width;
  27.             float heightScale = (float)Screen.height / height;
  28.             if (widthScale < heightScale) {
  29.                 Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
  30.             } else {
  31.                 Camera.main.orthographicSize = height / 2;
  32.             }
  33.  
  34.             detector = new ColorBlobDetector ();
  35.             spectrumMat = new Mat ();
  36.             //blobColorRgba = new Scalar (255);
  37.             blobColorHsv = new Scalar (255);
  38.             SPECTRUM_SIZE = new Size (200, 64);
  39.             CONTOUR_COLOR = new Scalar (255, 0, 0, 255);
  40.             CONTOUR_COLOR_WHITE = new Scalar (255, 255, 255, 255);
  41.  
  42.                
  43.         }
  44.  
  45.         public static Mat matFromBytes(int mFrameWidth, int mFrameHeight, byte[] data, bool grey, int type) {
  46.         // XXX: lo que aun no se bien es porque al crear el mat le da mayor
  47.         // altura que el valor original.
  48.         /*
  49.         CustomLog.d("matFromBytes", "CvType.CV_8UC1 = " + CvType.CV_8UC1);
  50.         CustomLog.d("matFromBytes", "CvType.CV_8UC2 = " + CvType.CV_8UC2);
  51.         CustomLog.d("matFromBytes", "CvType.CV_8UC3 = " + CvType.CV_8UC3);
  52.         CustomLog.d("matFromBytes", "CvType.CV_8UC4 = " + CvType.CV_8UC4);
  53.         */
  54.         // CV_8UC1 = grey
  55.         // CV_8UC4 = RGBA
  56.         // CV_8UC2 = RGB565
  57.         if (type == -1)
  58.             type = CvType.CV_8UC2;
  59.        
  60.         //int type = CvType.CV_8UC3;
  61.         //int type = 16;
  62.         if (grey)
  63.             type = CvType.CV_8UC1;
  64.        
  65.         //Mat m = new Mat(mFrameHeight + (mFrameHeight / 2), mFrameWidth, type);
  66.         //CustomLog.d(LOG_TAG, "matFromBytes - height = " + mFrameHeight + " - width = " + mFrameWidth + " - data len = " + data.length);
  67.         Mat m = new Mat(mFrameHeight, mFrameWidth, type);
  68.         m.put(0, 0, data); 
  69.         return m;      
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement