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++; } }
public float GetSimilarity(ISimilarSearcher similarSearcher) { var si = similarSearcher as SimilarSearcher; if (InputDataType != si.InputDataType) { throw new Exception("不是同一类型"); } var len = 0; var minLength = Math.Min(SimilarArray.Length, si.SimilarArray.Length); if (InputDataType == DataType.Data) { for (var i = 0; i < minLength; i++) { //if (Math.Abs(SimilarArray[i] - si.SimilarArray[i]) < 20) //{ // len++; //} var yihuo = SimilarArray[i] ^ si.SimilarArray[i]; len += CountOne(yihuo); } return(len / (float)SimilarArray.Length); } else { var dataCount = minLength / 4; for (var i = 0; i < dataCount; i++) { //var yihuo = SimilarArray[i] ^ si.SimilarArray[i]; //len += CountOne(yihuo); if (Math.Abs(SimilarArray[4 * i] - si.SimilarArray[4 * i]) > 40 || Math.Abs(SimilarArray[4 * i + 1] - si.SimilarArray[4 * i + 1]) > 40 || Math.Abs(SimilarArray[4 * i + 2] - si.SimilarArray[4 * i + 2]) > 40 || Math.Abs(SimilarArray[4 * i + 3] - si.SimilarArray[4 * i + 3]) > 40) { continue; } len++; //if (SimilarArray[i] == si.SimilarArray[i]) //{ // len++; //} } return(len / (float)dataCount); } }