Beispiel #1
0
        /**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization
            this.ObjectRecognitionConfigured = false;
            this.CurrentScanState            = ScanState.None;
#if ENABLE_WINMD_SUPPORT
            this.newCameraMatrices = false;
            this.worldAnchors      = new bool[this.artworkLimit]; // initialized with false
#endif
            this.artworks                     = new Dictionary <int, Artwork>();
            this.artists                      = new Dictionary <int, Artist>();
            this.videos                       = new Dictionary <int, Video>();
            this.audio                        = new Dictionary <int, Audio>();
            this.worldAnchorsLoaded           = false;
            this.newRoom                      = true;
            this.newData                      = false;
            this.recognitions                 = new Dictionary <int, Recognition>();
            this.instantiatedArtworks         = new Dictionary <int, GameObject>();
            this.recognizedArtworks           = new bool[this.artworkLimit]; // initialized with false
            this.fmModelOperations            = new Queue <FmModelOperationInfo>();
            this.isPerformingFmModelOperation = false;

            // Get reference to other scripts in the scene
            this.logger        = DebugLogger.Instance;
            this.dataLoader    = DataLoader.Instance;
            this.initializer   = Initializer.Instance;
            this.capture       = CaptureManager.IsInitialized ? CaptureManager.Instance.PhotoCapture : null;
            this.infoCanvas    = InfoCanvas.Instance;
            this.anchorManager = HoloToolkit.Unity.WorldAnchorManager.Instance;

            // Deactivate this script if necessary components are missing
            if ((this.scanningArea == null) || (this.artwork == null) || (this.debugPhoto == null) || (this.logger == null) || (this.initializer == null) ||
                (this.dataLoader == null) || (this.capture == null) || (this.infoCanvas == null) || (this.anchorManager == null))
            {
                Debug.LogError("ObjectRecognition: Script references not set properly.");
                this.enabled = false;
                return;
            }

            // Get the current camera resolution
            this.cameraResolution = this.capture.CameraResolution;
            this.logger.Log("Set new camera resolution: " + this.cameraResolution.width + " x " + this.cameraResolution.height);

#if ENABLE_WINMD_SUPPORT
            // Create a configuration object for Companion
            this.configuration = new CW.Configuration();

            // Configure image recognition
            CW.FeatureMatching feature        = new CW.FeatureMatching(CW.FeatureDetector.BRISK, CW.DescriptorMatcherType.BRUTEFORCE_HAMMING);
            CW.LSH             lsh            = new CW.LSH();
            CW.ShapeDetection  shapeDetection = new CW.ShapeDetection();

            // Configure image processing
            this.matchRecognition  = new CW.MatchRecognition(feature, CW.Scaling.SCALE_960x540);
            this.hashRecognition   = new CW.HashRecognition(shapeDetection, lsh);
            this.hybridRecognition = new CW.HybridRecognition(this.hashRecognition, feature, 70);

            // Set callback methods
            this.configuration.setResultCallback(this.ResultCallback, CW.ColorFormat.RGB);
            this.configuration.setErrorCallback(this.ErrorCallback);

            // Set number of frames to skip
            this.configuration.setSkipFrame(0);

            // Set image buffer
            this.configuration.setImageBuffer(1);

            // Add source to configuaration
            CW.ImageStream stream = new CW.ImageStream(1);
            this.configuration.setSource(stream);
#endif
        }