Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void OnVuforiaStarted()
- {
- CameraDevice.Instance.SetFrameFormat(mPixelFormat, true);
- CameraDevice.Instance.SetFocusMode(
- CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
- //Vuforia.Image arCamera = CameraDevice.Instance.GetCameraImage(mPixelFormat);
- imageVuforia = CameraDevice.Instance.GetCameraImage(mPixelFormat);
- Mat webCamTextureMat = matFromBytes(imageVuforia.Height, imageVuforia.Width, imageVuforia.Pixels, false, CvType.CV_8UC2);
- texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);
- gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
- gameObject.transform.localScale = new Vector3 (webCamTextureMat.cols (), webCamTextureMat.rows (), 1);
- if (fpsMonitor != null) {
- fpsMonitor.Add ("width", webCamTextureMat.width ().ToString ());
- fpsMonitor.Add ("height", webCamTextureMat.height ().ToString ());
- fpsMonitor.Add ("orientation", Screen.orientation.ToString ());
- fpsMonitor.consoleText = "Please touch the area of the open hand.";
- }
- float width = webCamTextureMat.width ();
- float height = webCamTextureMat.height ();
- float widthScale = (float)Screen.width / width;
- float heightScale = (float)Screen.height / height;
- if (widthScale < heightScale) {
- Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
- } else {
- Camera.main.orthographicSize = height / 2;
- }
- detector = new ColorBlobDetector ();
- spectrumMat = new Mat ();
- //blobColorRgba = new Scalar (255);
- blobColorHsv = new Scalar (255);
- SPECTRUM_SIZE = new Size (200, 64);
- CONTOUR_COLOR = new Scalar (255, 0, 0, 255);
- CONTOUR_COLOR_WHITE = new Scalar (255, 255, 255, 255);
- }
- public static Mat matFromBytes(int mFrameWidth, int mFrameHeight, byte[] data, bool grey, int type) {
- // XXX: lo que aun no se bien es porque al crear el mat le da mayor
- // altura que el valor original.
- /*
- CustomLog.d("matFromBytes", "CvType.CV_8UC1 = " + CvType.CV_8UC1);
- CustomLog.d("matFromBytes", "CvType.CV_8UC2 = " + CvType.CV_8UC2);
- CustomLog.d("matFromBytes", "CvType.CV_8UC3 = " + CvType.CV_8UC3);
- CustomLog.d("matFromBytes", "CvType.CV_8UC4 = " + CvType.CV_8UC4);
- */
- // CV_8UC1 = grey
- // CV_8UC4 = RGBA
- // CV_8UC2 = RGB565
- if (type == -1)
- type = CvType.CV_8UC2;
- //int type = CvType.CV_8UC3;
- //int type = 16;
- if (grey)
- type = CvType.CV_8UC1;
- //Mat m = new Mat(mFrameHeight + (mFrameHeight / 2), mFrameWidth, type);
- //CustomLog.d(LOG_TAG, "matFromBytes - height = " + mFrameHeight + " - width = " + mFrameWidth + " - data len = " + data.length);
- Mat m = new Mat(mFrameHeight, mFrameWidth, type);
- m.put(0, 0, data);
- return m;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement