예제 #1
0
        public static void SearchPictures(ISimilarSearcher sourceSearcher)
        {
            var files      = Directory.GetFiles(@"F:\照片\弯弯", "*.JPG");
            var outputPath = Path.GetFullPath($@"output\7");

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            //var index =0;
            // foreach (var f in files)
            for (var index = 300; index < files.Length; index++)
            {
                var file     = files[index];
                var searcher = SimilarSearchLoader.Creator();
                using (var bitmap = new Bitmap(file))
                {
                    _ = searcher.GetEigenvalue(bitmap, PoolingType.Mean, Color.Black, precisionX: 10, precisionY: 10);
                    var similar = searcher.GetSimilarity(sourceSearcher);
                    if (similar >= 0.75f)
                    {
                        File.Copy(file, $@"{outputPath}\{similar * 100}__{index}.jpg");
                    }
                    Console.WriteLine($"比较完成第{index}张,共{files.Length}张;相似度:{similar}");
                }
                //index++;
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var filePath = @"F:\照片\弯弯\IMG_3006.JPG";
            //var filePath2 = @"C:\Users\Dustray\Desktop\IMG_2994.JPG";
            var    filePath2 = @"F:\照片\弯弯\IMG_0686.JPG";
            var    searcher1 = SimilarSearchLoader.Creator();
            var    searcher2 = SimilarSearchLoader.Creator();
            string str1;
            string str2;

            byte[] bytes1;
            byte[] bytes2;
            byte[,,] p1;
            byte[,,] p2;

            var timewatcher    = new Stopwatch();
            var timewatcherAll = new Stopwatch();

            timewatcherAll.Start();
            timewatcher.Start();
            using (var bitmap = new Bitmap(filePath))
            {
                bytes1 = searcher1.GetEigenvalue(bitmap, PoolingType.Mean, Color.Black, precisionX: 10, precisionY: 10);
                p1     = searcher1.GetPoolColor();
                str1   = System.Text.Encoding.Default.GetString(bytes1);
            }
            //SearchPictures(searcher1);
            //Console.Read();
            //return;
            timewatcher.Stop();
            Console.WriteLine($"计算第一张图片特征值时间:{timewatcher.Elapsed}");
            timewatcher.Restart();

            using (var bitmap = new Bitmap(filePath2))
            {
                bytes2 = searcher2.GetEigenvalue(bitmap, PoolingType.Mean, Color.Black, precisionX: 10, precisionY: 10);
                p2     = searcher2.GetPoolColor();
                str2   = System.Text.Encoding.Default.GetString(bytes2);
            }
            timewatcher.Stop();
            Console.WriteLine($"计算第二张图片特征值时间:{timewatcher.Elapsed}");
            timewatcher.Restart();

            if (str1 == str2)
            {
            }
            SaveToImage(Path.GetFullPath("p1.bmp"), p1);
            SaveToImage(Path.GetFullPath("p2.bmp"), p2);
            timewatcher.Stop();
            Console.WriteLine($"保存临时图片特征值时间:{timewatcher.Elapsed}");
            timewatcher.Restart();

            var similar = searcher1.GetSimilarity(searcher2);

            timewatcher.Stop();
            Console.WriteLine($"计算相似度时间:{timewatcher.Elapsed}");

            timewatcherAll.Stop();
            Console.WriteLine($"总运行时间:{timewatcherAll.Elapsed}");
            Console.WriteLine($"\r\n相似比例:{similar}");
            Console.Read();
        }