Esempio n. 1
0
        //private static string[] GetfilesFromDirectory(string folder)
        //{
        //    List<string> files = Directory.GetFiles(folder).ToList();
        //    List<String> removeList = new List<string>();
        //    for (int i = 0; i < files.Count; i++)
        //    {
        //        if(files[i].EndsWith("ini"))
        //            removeList.Add(files[i]);
        //    }
        //    foreach (string path in removeList)
        //    {
        //        files.Remove(path);
        //    }
        //    return files.ToArray();
        //}
        private static int HandleIdenticalVectorWithDifferentChoise(ref List<string> aFiles, ref List<string> tFiles, ref List<string> fFiles, VectorRepository rep, Testing.HandleIdenticalMethod identical)
        {
            if (identical == Testing.HandleIdenticalMethod.Ignore)
                return -1;

            ImageVector tVector;
            ImageVector fVector;
            string tVectorC;
            string fVectorC;
            bool same;
            int count = 0;

            for (int t = 0; t < tFiles.Count; t++)
                for (int f = 0; f < fFiles.Count; f++)
                {
                    if (tFiles[t] == "" || fFiles[f] == "")
                        continue;

                    tVector = null;
                    fVector = null;
                    same = true;

                    // Load Images as vectors
                    tVector = rep.getVectorByPath(tFiles[t]);
                    fVector = rep.getVectorByPath(fFiles[f]);
                    if (tVector == null || fVector == null)
                        throw (new Exception("Unexpected Error: a picture was not found in repository"));

                    // Classify
                    tVectorC = Classifier.ClassifyVector(tVector);
                    fVectorC = Classifier.ClassifyVector(fVector);

                    // Check similarity
                    for (int c=0; c < ImageVector.NUMBER_OF_PARAMETERS; c++)
                        if (tVectorC[c] != fVectorC[c])
                        {
                            same = false;
                            break;
                        }

                    // Handle identical vectors (Mark as empty for removel)
                    if (same)
                    {
                        count++;
                        switch (identical)
                        {
                            case Testing.HandleIdenticalMethod.Remove:
                                aFiles.Remove(tFiles[t]);
                                aFiles.Remove(fFiles[f]);
                                tFiles[t] = "";
                                fFiles[f] = "";
                                break;
                        }
                    }
                }

            // Remove marked
            while (tFiles.Remove(""));
            while (fFiles.Remove(""));

            return count;
        }
Esempio n. 2
0
        /// <summary>
        /// predicts for all images in folder if true or false (For testing, using given repository to retrive already scanned images)
        /// </summary>
        /// <param name="folder">path to folder with images to predict</param>
        /// <param name="res">keeps for each image if true or falde</param>
        /// <returns>true if decision was successful. else false.</returns>
        public bool DecideForTesting(List<string> allFiles, VectorRepository rep, out double[] res)
        {
            res = null;
            // Get list of files in folders
            String[] files = allFiles.ToArray();
            DecisionListcount = 0;
            String[] cVectors = new string[files.Length];
            double[] results;
            ImageVector vector;
            List<ImageVector> vectorList = new List<ImageVector>();

            for (int i = 0; i < files.Length; i++)
            {
                //get imageVectors
                vector = rep.getVectorByPath(files[i]);
                if (vector == null)
                    vector = new ImageVector(files[i], ParameterList);

                vectorList.Add(vector);
                DecisionListcount++;
            }

            //load algorithm data and predict
            //if (!_algorithm.LoadData())
            //{
            //    return false;
            //}

            if (!Algorithm.Predict(vectorList, out results))
                return false;

            res = results;
            return true;
        }
Esempio n. 3
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;
        }