/// <summary> /// Raises the web cam texture to mat helper initialized event. /// </summary> public void OnWebCamTextureToMatHelperInitialized() { UnityEngine.Debug.Log("OnWebCamTextureToMatHelperInitialized"); OpenCVForUnity.CoreModule.Mat webCamTextureMat = webCamTextureToMatHelper.GetMat(); 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); UnityEngine.Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (fpsMonitor != null) { fpsMonitor.Add("width", webCamTextureMat.width().ToString()); fpsMonitor.Add("height", webCamTextureMat.height().ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); } 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; } matOpFlowThis = new OpenCVForUnity.CoreModule.Mat(); matOpFlowPrev = new OpenCVForUnity.CoreModule.Mat(); MOPcorners = new MatOfPoint(); mMOP2fptsThis = new MatOfPoint2f(); mMOP2fptsPrev = new MatOfPoint2f(); mMOP2fptsSafe = new MatOfPoint2f(); mMOBStatus = new MatOfByte(); mMOFerr = new MatOfFloat(); }
public void OnWebCamTextureToMatHelperInitialized() { Debug.Log("OnWebCamTextureToMatHelperInitialized"); var webCamTextureMat = _toMatHelper.GetMat(); QuadTex = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGBA32, false); GetComponent <Renderer>().material.mainTexture = QuadTex; Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (_fpsMonitor != null) { _fpsMonitor.Add("width", webCamTextureMat.width().ToString()); _fpsMonitor.Add("height", webCamTextureMat.height().ToString()); _fpsMonitor.Add("orientation", Screen.orientation.ToString()); } float width = webCamTextureMat.width(); float height = webCamTextureMat.height(); float widthScale = Screen.width / width; float heightScale = Screen.height / height; if (widthScale < heightScale) { Camera.main.orthographicSize = (width * Screen.height / Screen.width) / 2; } else { Camera.main.orthographicSize = height / 2; } //Quadを画面いっぱいにリサイズ //https: //blog.narumium.net/2016/12/11/unityでスマホカメラを全面表示する/ var quadHeight = Camera.main.orthographicSize * 2; var quadWidth = quadHeight * Camera.main.aspect; gameObject.transform.localScale = new Vector3(quadWidth, quadHeight, 1); IsInitialized = true; }
/// <summary> /// Raises the webcam texture to mat helper initialized event. /// </summary> public void OnWebCamTextureToMatHelperInitialized() { Debug.Log("OnWebCamTextureToMatHelperInitialized"); Mat webCamTextureMat = webCamTextureToMatHelper.GetMat(); Mat downscaleMat = imageOptimizationHelper.GetDownScaleMat(webCamTextureMat); 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); // Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (fpsMonitor != null) { fpsMonitor.Add("width", webCamTextureMat.width().ToString()); fpsMonitor.Add("height", webCamTextureMat.height().ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); fpsMonitor.Add("downscaleRaito", imageOptimizationHelper.downscaleRatio.ToString()); fpsMonitor.Add("frameSkippingRatio", imageOptimizationHelper.frameSkippingRatio.ToString()); fpsMonitor.Add("downscale_width", downscaleMat.width().ToString()); fpsMonitor.Add("downscale_height", downscaleMat.height().ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); } //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; //} rgbaMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC4); bgrMat = new Mat(downscaleMat.rows(), downscaleMat.cols(), CvType.CV_8UC3); //Main Process Process(); }
/// <summary> /// Raises the webcam texture to mat helper initialized event. /// </summary> public void OnWebCamTextureToMatHelperInitialized() { Debug.Log("OnWebCamTextureToMatHelperInitialized"); Mat webCamTextureMat = webCamTextureToMatHelper.GetMat(); 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); // Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (fpsMonitor != null) { fpsMonitor.Add("deviceName", webCamTextureToMatHelper.GetDeviceName().ToString()); fpsMonitor.Add("width", webCamTextureToMatHelper.GetWidth().ToString()); fpsMonitor.Add("height", webCamTextureToMatHelper.GetHeight().ToString()); // fpsMonitor.Add ("videoRotationAngle", webCamTextureToMatHelper.GetWebCamTexture ().videoRotationAngle.ToString ()); // fpsMonitor.Add ("videoVerticallyMirrored", webCamTextureToMatHelper.GetWebCamTexture ().videoVerticallyMirrored.ToString ()); fpsMonitor.Add("camera fps", webCamTextureToMatHelper.GetFPS().ToString()); fpsMonitor.Add("isFrontFacing", webCamTextureToMatHelper.IsFrontFacing().ToString()); fpsMonitor.Add("rotate90Degree", webCamTextureToMatHelper.rotate90Degree.ToString()); fpsMonitor.Add("flipVertical", webCamTextureToMatHelper.flipVertical.ToString()); fpsMonitor.Add("flipHorizontal", webCamTextureToMatHelper.flipHorizontal.ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); } // 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; // } grayMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC1); faces = new MatOfRect(); }
/// <summary> /// Raises the webcam texture initialized event. /// </summary> private void OnInited() { prevPos = new Vector2(webCamTexture.width / 2, webCamTexture.height); if (colors == null || colors.Length != webCamTexture.width * webCamTexture.height) { colors = new Color32[webCamTexture.width * webCamTexture.height]; } if (texture == null || texture.width != webCamTexture.width || texture.height != webCamTexture.height) { //texture = new Texture2D (webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false); texture = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false); } rgbaMat = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4); /* * rgbaMat2 = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4); * rgbaMat3 = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4); * rgbaMatFinal = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4); */ rgbaMat2 = new Mat(requestedHeight, requestedWidth, CvType.CV_8UC4); rgbaMat3 = new Mat(requestedHeight, requestedWidth, CvType.CV_8UC4); rgbaMatFinal = new Mat(requestedHeight, requestedWidth, CvType.CV_8UC4); gameObject.GetComponent <Renderer> ().material.mainTexture = texture; gameObject.transform.localScale = new Vector3(webCamTexture.width, webCamTexture.height, 1); Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (fpsMonitor != null) { fpsMonitor.Add("width", rgbaMat.width().ToString()); fpsMonitor.Add("height", rgbaMat.height().ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); } float width = rgbaMat.width(); float height = rgbaMat.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; } KF = new KalmanFilter(4, 2, 0, CvType.CV_32FC1); // intialization of KF... Mat transitionMat = new Mat(4, 4, CvType.CV_32F); transitionMat.put(0, 0, new float[] { 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1 }); KF.set_transitionMatrix(transitionMat); measurement = new Mat(2, 1, CvType.CV_32FC1); measurement.setTo(Scalar.all(0)); cursorPos = new Point(); GetCursorPos(cursorPos); // Set initial state estimate. Mat statePreMat = KF.get_statePre(); statePreMat.put(0, 0, new float[] { (float)cursorPos.x, (float)cursorPos.y, 0, 0 }); Mat statePostMat = KF.get_statePost(); statePostMat.put(0, 0, new float[] { (float)cursorPos.x, (float)cursorPos.y, 0, 0 }); Mat measurementMat = new Mat(2, 4, CvType.CV_32FC1); Core.setIdentity(measurementMat); KF.set_measurementMatrix(measurementMat); Mat processNoiseCovMat = new Mat(4, 4, CvType.CV_32FC1); Core.setIdentity(processNoiseCovMat, Scalar.all(1e-4)); KF.set_processNoiseCov(processNoiseCovMat); Mat measurementNoiseCovMat = new Mat(2, 2, CvType.CV_32FC1); Core.setIdentity(measurementNoiseCovMat, Scalar.all(10)); KF.set_measurementNoiseCov(measurementNoiseCovMat); Mat errorCovPostMat = new Mat(4, 4, CvType.CV_32FC1); Core.setIdentity(errorCovPostMat, Scalar.all(.1)); KF.set_errorCovPost(errorCovPostMat); /*Imgproc.rectangle ( * rgbaMatFinal, * new Point (0, 0), * new Point (rgbaMatFinal.width (), rgbaMatFinal.height ()), * new Scalar (0, 0, 0, 255), -1); */ }