Beispiel #1
0
        // Scan image to reporistory
        public static bool scanPicturesIntoReporistory(string folderAll, string folderTrue, VectorRepository rep, Dictionary<ImageVector.ImageParameters,bool> parameterList)
        {
            // Get list of files in folders
            ProgressString = "Starting picture scan..";

            List<string> allFiles, falseFiles, trueFiles;
            try
            {
                allFiles = LoadImages(folderAll).ToList();
                trueFiles = LoadImages(folderTrue).ToList();

                falseFiles = SubstractListsByFileName(allFiles, trueFiles);
                trueFiles = SubstractListsByFileName(allFiles, falseFiles);  // In order for the path to be via 'allFiles' folder
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                return false;
            }

            int numOfFiles = allFiles.Count();
            int completed = 0;
            _progress = 0;

            // Scan files
            ImageVector existing;
            List<ImageVector> newTrue = new List<ImageVector>();
            List<ImageVector> newFalse = new List<ImageVector>();
            foreach (string path in trueFiles)
            {
                ProgressString = "Checking if " + path + "is already scanned..";
                existing = rep.getVectorByPath(path);
                if (existing == null && File.Exists(path))
                {
                    ProgressString = "Scanning " + path;
                    ImageVector vec = new ImageVector(path, parameterList);
                    newTrue.Add(vec);
                }
                completed++;
                _progress = (int)((completed * 100) / numOfFiles);
            }
            foreach (string path in falseFiles)
            {
                ProgressString = "Checking if " + path + "is already scanned..";
                existing = rep.getVectorByPath(path);
                if (existing == null && File.Exists(path))
                {
                    ProgressString = "Scanning " + path;
                    ImageVector vec = new ImageVector(path, parameterList);
                    newFalse.Add(vec);
                }
                completed++;
                _progress = (int)((completed * 100) / numOfFiles);
            }
            ProgressString = "Scan done. Saving scanned pictures.";

            // Add to repository
            rep.AddToList(newTrue, newFalse);

            ProgressString = "Done scanning";
            return true;
        }
Beispiel #2
0
        /// <summary>
        /// trains algorithm
        /// </summary>
        /// <param name="cVectorsTrue"></param>
        /// <param name="cVectorsFalse"></param>
        /// <returns>true always</returns>
        public override bool Train(List<ImageVector> vectorsTrue, List<ImageVector> vectorsFalse)
        {
            //delete the test repository if it exists
            if(Directory.Exists("knnTest'sVectorData"))
                Directory.Delete("knnTest'sVectorData", true);

             //create repository only for knn learning
            _testingRepository = new VectorRepository("knnTest");
            _testingRepository.delete();
            _testingRepository.AddToList(vectorsTrue, vectorsFalse);

            return true;
        }