// Use this for initialization void Start() { // DepthEstimator のセットアップ // TODO: factory等にまとめた方がよさそう #if UNITY_UWP depthEstimator = new FastDepthEstimator(FastDepthOnnxModel); #else depthEstimator = new DummyDepthEstimator(); #endif // カメラパラメータの取得 var cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending(res => res.width * res.height).First(); cameraParameters = new CameraParameters { hologramOpacity = 0.0f, cameraResolutionWidth = cameraResolution.width, cameraResolutionHeight = cameraResolution.height, pixelFormat = CapturePixelFormat.BGRA32, }; Debug.Log(string.Format("Camera[width:{0}, height:{1}]", cameraParameters.cameraResolutionWidth, cameraParameters.cameraResolutionHeight)); // バッファの確保 inputTensor = new float[depthEstimator.InputHeight * depthEstimator.InputWidth * 3]; inputTexture = new Texture2D( depthEstimator.InputWidth, depthEstimator.InputHeight, TextureFormat.RGB24, false); depthTexture = new Texture2D( depthEstimator.InputWidth, depthEstimator.InputHeight, TextureFormat.RGB24, false); // triangles = ImageUtil.MakeTriangles(depthEstimator.InputWidth, depthEstimator.InputHeight); vertices = new Vector3[depthEstimator.InputWidth * depthEstimator.InputHeight]; Debug.Log(string.Format("num mertices: {0} ", vertices.Length)); Debug.Log("Alloc texture buffer."); targetTexture = new Texture2D(cameraParameters.cameraResolutionWidth, cameraParameters.cameraResolutionHeight); CropWidth = Math.Min(CropWidth, cameraParameters.cameraResolutionWidth); CropHeight = Math.Min(CropHeight, cameraParameters.cameraResolutionHeight); var srcSize = new Vector2(targetTexture.width, targetTexture.height); var srcRoi = new Rect(targetTexture.width / 2 - CropWidth / 2, targetTexture.height / 2 - CropHeight / 2, CropWidth, CropHeight); var destSize = new Vector2(depthEstimator.InputWidth, depthEstimator.InputHeight); // テンソル => スクリーン座標 をあらかじめ計算しておく screenPos = new Vector2[depthEstimator.InputHeight, depthEstimator.InputWidth]; for (var y = 0; y < depthEstimator.InputHeight; ++y) { for (var x = 0; x < depthEstimator.InputWidth; ++x) { var invY = depthEstimator.InputHeight - y - 1; ImageUtil.CalcSrcPos(srcSize, srcRoi, destSize, x, invY, out screenPos[y, x].x, out screenPos[y, x].y); } } // 何も無い場所をエアタップできるように GlobalListener へ登録 InputManager.Instance.AddGlobalListener(gameObject); }
/// <summary> /// Initializes a new instance of the flooding warning system. /// </summary> /// <param name="speedEstimator">Speed estimator.</param> /// <param name="depthEstimator">Depth estimator.</param> /// <param name="localWarner">Local warner.</param> public FloodingWarningSystem(ISpeedEstimator speedEstimator, IDepthEstimator depthEstimator, ILocalWarner localWarner) { Deploy(speedEstimator); Deploy(depthEstimator); Deploy(localWarner); InitializeMonitoringHooks(); }
/// <summary> /// Deploy the specified depthEstimator as the new estimator for depth. /// </summary> /// <param name="depthEstimator">Depth estimator.</param> public void Deploy(IDepthEstimator depthEstimator) { this.depthEstimator = depthEstimator; }