Beispiel #1
0
        /**
         * Create a 'Configuration' wrapper object.
         *
         * @param algorithm
         * @return returns a 'Configuration' wrapper object asynchronously
         */
        private IAsyncAction CreateConfiguration(ImageProcessingMethod processingMethod)
        {
            return(Task.Run(() => {
                this.configuration = new CW.Configuration();

                // Create algorithms
                CW.FeatureMatching feature = new CW.FeatureMatching(CW.FeatureDetector.BRISK, CW.DescriptorMatcherType.BRUTEFORCE_HAMMING);
                CW.LSH lsh = new CW.LSH();
                CW.ShapeDetection polygonDetection = new CW.ShapeDetection();
                CW.ShapeDetection quadDetection = new CW.ShapeDetection(4, 4, "Quad");

                // Configure image processing
                CW.MatchRecognition matchRecognition = new CW.MatchRecognition(feature, CW.Scaling.SCALE_640x360);
                CW.HashRecognition hashRecognition = new CW.HashRecognition(polygonDetection, lsh);
                CW.HybridRecognition hybridRecognition = new CW.HybridRecognition(hashRecognition, feature, 50);
                CW.ObjectDetection objectDetection = new CW.ObjectDetection(quadDetection);

                // Set callback methods (result image should have an alpha channel (required for WritableBitmap))
                this.configuration.setResultCallback(this.ResultCallback, CW.ColorFormat.BGRA);
                this.configuration.setErrorCallback(this.ErrorCallback);

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

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

                // Add source to configuaration
                CW.ImageStream stream = new CW.ImageStream(30);
                this.configuration.setSource(stream);

                // Create image models
                string model0 = this.assets.Path + "\\poster_left.jpg";
                string model1 = this.assets.Path + "\\poster_right.jpg";
                matchRecognition.addModel(new CW.FeatureMatchingModel(model0, 0));
                matchRecognition.addModel(new CW.FeatureMatchingModel(model1, 1));
                hashRecognition.addModel(model0, 0);
                hashRecognition.addModel(model1, 1);
                hybridRecognition.addModel(model0, 0);
                hybridRecognition.addModel(model1, 1);

                // Choose processing method
                switch (processingMethod)
                {
                case ImageProcessingMethod.FEATUE_MATCHING:
                    this.configuration.setProcessing(matchRecognition);
                    break;

                case ImageProcessingMethod.IMAGE_HASHING:
                    this.configuration.setProcessing(hashRecognition);
                    break;

                case ImageProcessingMethod.HYBRID_MATCHING:
                    this.configuration.setProcessing(hybridRecognition);
                    break;

                case ImageProcessingMethod.SHAPE_DETECTION:
                    this.configuration.setProcessing(objectDetection);
                    break;

                default:
                    throw new Exception("Image processing method not found.");
                }
            }).AsAsyncAction());
        }
Beispiel #2
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
        }