Beispiel #1
0
        /// <summary>
        /// Raises the load button event.
        /// </summary>
        public void OnLoadButton()
        {
            Debug.Log("User clicked [Load] button.");

            // Restart everything!
            dispose();

            if (facerecAlgorithm == "FaceRecognizer.Fisherfaces")
            {
                model = Face.createFisherFaceRecognizer();
            }
            else if (facerecAlgorithm == "FaceRecognizer.Eigenfaces")
            {
                model = Face.createEigenFaceRecognizer();
            }

            if (model == null)
            {
                Debug.LogError("ERROR: The FaceRecognizer algorithm [" + facerecAlgorithm + "] is not available in your version of OpenCV. Please update to OpenCV v2.4.1 or newer.");
                m_mode = MODES.MODE_DETECTION;
                return;
            }

            // load the train data.
            model.load(Application.temporaryCachePath + "/traindata.yml");

            int maxLabel = (int)Core.minMaxLoc(model.getLabels()).maxVal;

            if (maxLabel <= 0)
            {
                Debug.Log("load failure.");
                model.Dispose();
                model  = null;
                m_mode = MODES.MODE_DETECTION;
                return;
            }

            // Restore the save data.
            m_numPersons = maxLabel + 1;
            for (int i = 0; i < m_numPersons; ++i)
            {
                m_latestFaces.Add(i);
                preprocessedFaces.Add(Imgcodecs.imread(Application.temporaryCachePath + "/preprocessedface" + i + ".jpg", 0));
                if (preprocessedFaces [i].empty())
                {
                    preprocessedFaces [i] = new Mat(faceHeight, faceWidth, CvType.CV_8UC1, new Scalar(128));
                }
                faceLabels.Add(i);
            }

            // go to the recognition mode!
            m_mode = MODES.MODE_RECOGNITION;
        }