public void StitcherPrimitiveTest() { var shreds = Shred.Factory("Shred", Path.Combine(Drive.GetDriveRoot(), Dir.StitcherTestDirectory, "PrimitiveTest"), false); var bitmap = Stitcher.Merge(shreds); bitmap.Save("StitcherPrimitiveTest.png", ImageFormat.Png); }
public void StitcherArtificialTest() { var shreds = Shred.Factory("image", Path.Combine(Drive.GetDriveRoot(), Dir.ArtificialTestDirectory, Dir.ArtificialHttpDocument), false); var bitmap = Stitcher.Merge(shreds); bitmap.Save("StitcherArtificialTest.png", ImageFormat.Png); }
public void NaiveKruskalArtificial() { Shred.BUFFER = 0; Shred.SAMPLE_SIZE = 4; var path = Path.Combine(Drive.GetDriveRoot(), Dir.ArtificialTestDirectory, Dir.NaiveKruskalHttpDocument); var shreds = Shred.Factory("image", path, false); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); var checker = Helpers.BuildChecker(Path.Combine(path, Helpers.CheckFile)); shreds.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); results.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); var indicies = results.Select((t, pos) => new Tuple <int, Shred>(pos, t)).ToList(); var result = indicies.Select(pair => { var filename = Path.GetFileName(pair.Item2.Filepath); Assert.IsNotNull(filename); Assert.IsNotNull(checker[filename]); var expected = checker[filename]; var actual = pair.Item1; Console.WriteLine("Actual " + actual + " vs. " + expected + " | File: " + filename); return(actual.ToString(CultureInfo.InvariantCulture) == expected); }).ToList(); // var diff = Differ.DiffShredByOrder(results.Select(shred => shred.Id).ToList(), //Enumerable.Range(0, results.Count).Select(ii => (long)ii).ToList()); // Console.WriteLine("Difference : " + diff); ExportResult((Cluster)shreds.First().Root(), "../../visualizer/NaiveKruskalArtifical.png"); }
public static List <Tuple <Shred, int> > LoadShredsRandomized(List <string> filenames, bool runOcr = true) { var randomizedFilenames = Shuffle(filenames); var shreds = Shred.Factory(randomizedFilenames.Select(pair => pair.Item1).ToList(), runOcr); return(randomizedFilenames.Zip(shreds, (pair, shred) => Tuple.Create(shred, pair.Item2)).ToList()); }
public static List <Shred> InitializeShreds(bool runOcr = false) { Console.WriteLine("Building Shreds"); var path = Path.Combine(Drive.GetDriveRoot(), Dir.CarusoTestDirectory, Dir.FewTestMaterials); var shreds = Shred.Factory("image", path, runOcr); return(shreds); }
public static List <Shred> BootstrapPrimitiveThree() { Console.WriteLine("Building Shreds"); var path = Path.Combine(Drive.GetDriveRoot(), Dir.PrimitiveTestDirectory, Dir.PrimitiveTestThreeNormal); var shreds = Shred.Factory("Shred", path, false); return(shreds); }
public static void ShredFactory(string filepath) { Shred shred = new Shred(filepath, false); shred.VisualizeChamfers(Direction.FromLeft); shred.VisualizeChamfers(Direction.FromRight); shred.VisualizeChamfers(Direction.FromTop); shred.VisualizeChamfers(Direction.FromBottom); }
private void BtnRemoveShred_OnClick(object sender, RoutedEventArgs e) { List <Model_Shred> lstSelectedItems = new List <Model_Shred>(); foreach (Model_Shred item in lvShredFolderPath.SelectedItems) { lstSelectedItems.Add(item); } Shred.Command_RemoveFolder_Click(lstSelectedItems); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { Trace.WriteLine("Application Loaded"); Pie3.Data = Home.SafeCleaningData; Command_Start_Click(); CleanerML.CommandCollapseAllClick(); BackgroundWorker bgCheckforUpdatesWorker = new BackgroundWorker(); bgCheckforUpdatesWorker.DoWork += new DoWorkEventHandler(bgCheckforUpdatesWorker_DoWork); bgCheckforUpdatesWorker.RunWorkerAsync(); // check if an update is required after being prechecked at App.xaml.cs if (StaticResources.strShredLocation == string.Empty) { if (Settings.Default.ClamWin_Update) { CommandLogic_Clam.I.LaunchUpdater(); } else // none { // then check if it requires an update at startup if (Settings.Default.ClamWin_UpdateDBAtStartup) { CommandLogic_Clam.I.LaunchUpdater(); } } } else { Shred.Command_ShowWindow_Click(); Shred.BlnIsApplicationNeedtoClose = true; Shred.ShredFilesCollection.Add(new Model_Shred() { FilePath = StaticResources.strShredLocation }); Shred.Command_ShredStart_Click(); FileAttributes attr = File.GetAttributes(StaticResources.strShredLocation); if (attr.HasFlag(FileAttributes.Directory)) { MessageBox.Show( "Shredding is done successfully for the folder: " + StaticResources.strShredLocation, "mCleaner", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Shredding is done successfully for file : " + StaticResources.strShredLocation, "mCleaner", MessageBoxButton.OK, MessageBoxImage.Information); } Application.Current.Shutdown(); } ProgressWorker.I.Start(); }
public static void Reconstruct(string prefix, string dir, bool display) { Console.WriteLine("Loading Shreds"); var shreds = Shred.Factory(prefix, dir, false); Console.WriteLine("Comparing And Clusering"); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); Console.WriteLine("Exporting Results"); NaiveKruskalTests.ExportResult((Cluster)results.First().Root(), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "output.png"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "json.js")); }
public void ShredSerializingTest() { // Create a Square Point[] patch1 = new Point[4]; patch1[0] = new Point(0, 0); patch1[1] = new Point(0, 10); patch1[2] = new Point(99, 10); patch1[3] = new Point(99, 0); Point[] patch2 = new Point[4]; patch2[0] = new Point(0, 50); patch2[1] = new Point(0, 60); patch2[2] = new Point(99, 60); patch2[3] = new Point(99, 50); // Create an Original Image var original = new Image <Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(patch1, new Bgr(Color.Gray)); original.FillConvexPoly(patch2, new Bgr(Color.Gray)); // Ensure filepaths are clear for writing files const string filepath = "shredtest.bmp"; const string serializedpath = "test.shred"; if (File.Exists(filepath)) { File.Delete(filepath); } original.ToBitmap().Save(filepath); Assert.IsTrue(File.Exists(filepath)); Shred myshred = new Shred(filepath); if (File.Exists(serializedpath)) { File.Delete(serializedpath); } // Save and load shred Assert.IsFalse(File.Exists(serializedpath)); Shred.Save(myshred, serializedpath); Assert.IsTrue(File.Exists(serializedpath)); Shred newshred = Shred.Load(serializedpath); Assert.IsTrue(newshred.Sparsity[(int)Direction.FromLeft] == myshred.Sparsity[(int)Direction.FromLeft]); }
public void OcrFullOrientationTest() { const string docRev = @"Documents\EnergyInfrastructure\Full2"; const string docReg = @"Documents\IncomeTax_Ingalls\Full1"; var driveRev = new Drive(docRev, Drive.Reason.Read); var driveReg = new Drive(docReg, Drive.Reason.Read); var revs = Shred.Factory(driveRev.Files("image").ToList(), true); var regs = Shred.Factory(driveReg.Files("image").ToList(), true); var resV = revs.Select(shred => { Console.Write(" | Expected:" + Orientation.Reversed); Console.Write(" | Actual: " + (shred.TrueOrienation.ToString())); Console.Write(" | Orientation Confidence: " + shred.OrientationConfidence); if (shred.TrueOrienation == null) { Console.WriteLine(" | Empty? =" + shred.IsEmpty); Console.WriteLine("Correct? Indeterminable"); return(true); } var passed = (Orientation.Reversed == shred.TrueOrienation || shred.IsEmpty); Console.WriteLine(" | Empty? =" + shred.IsEmpty); Console.WriteLine("Correct? = " + passed); return(passed); }).ToList(); var resG = regs.Select(shred => { Console.Write(" | Expected:" + Orientation.Regular); Console.Write(" | Actual: " + (shred.TrueOrienation.ToString())); Console.Write(" | Orientation Confidence: " + shred.OrientationConfidence); if (shred.TrueOrienation == null) { Console.WriteLine(" | Empty? =" + shred.IsEmpty); Console.WriteLine("Correct? Indeterminable"); return(true); } var passed = Orientation.Regular == shred.TrueOrienation || shred.IsEmpty; Console.WriteLine(" | Empty? =" + shred.IsEmpty); Console.WriteLine("Correct? = " + passed); return(passed); }).ToList(); Assert.IsTrue(resV.All(item => item)); Assert.IsTrue(resG.All(item => item)); }
public void TestQueue() { var max = 1.00; var path = Path.Combine(Drive.GetDriveRoot(), Dir.PdfRequiremnetTestDirectory, Dir.PdfRequiremnetTestFullOne); var shreds = Shred.Factory("image", path, false); var queue = Reconstructor.BuildQueue(shreds); while (queue.Count > 0) { var next = queue.Dequeue().ChamferSimilarity; Assert.IsTrue(next <= max); Console.WriteLine(next); max = next; } }
public void NaiveKruskalAuthentic() { var path = Path.Combine(Drive.GetDriveRoot(), Dir.PdfRequiremnetTestDirectory, Dir.PdfRequiremnetTestFullOne); var shreds = Shred.Factory("image", path, false); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); shreds.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); results.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); var diff = Differ.DiffShredByOrder(results.Select(shred => shred.Id).ToList(), Enumerable.Range(0, results.Count).Select(ii => (long)ii).ToList()); Console.WriteLine("Difference : " + diff); ExportResult((Cluster)results.First().Root(), "../../visualizer/NaiveKruskalAuthentic.png"); }
public void ShredFactoryTest() { Console.WriteLine("Loading File from TestDrive And From Factory Independently"); var relativeDirectory = Path.Combine(CarusoTestDirectory, CarusoTestMaterialsFolder); var fullDirectory = Path.Combine(Drive.GetDriveRoot(), relativeDirectory); var mydrive = new Drive(relativeDirectory, Drive.Reason.Read); var shreds = Shred.Factory("image", fullDirectory); Assert.IsTrue(shreds.Count == mydrive.FileCount("image")); foreach (Shred shred in shreds) { Assert.IsTrue(File.Exists(shred.Filepath)); } Console.WriteLine("Factory Test Successful"); }
public string Reconstruct(string prefix, string dir, bool display) { StringBuilder sb = new StringBuilder(); WriteToLog("Loading Shreds"); var shreds = Shred.Factory(prefix, dir, false); WriteToLog("Comparing And Clusering"); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); WriteToLog("Exporting Results"); string currentDir = Directory.GetCurrentDirectory(); NaiveKruskalTests.ExportResult((Cluster)results.First().Root(), Path.Combine(currentDir, "output.png"), Path.Combine(currentDir, "json.js")); WriteToLog("Export Complete"); return(sb.ToString()); }
public void OcrEmptyDetectionTest() { //Load Shreds var abspath = Path.Combine(Drive.GetDriveRoot(), Dir.OcrDirectory, Dir.OcrEmptyTestDirectory); var shreds = Shred.Factory("empty", abspath, true); var checker = Helpers.BuildChecker(Path.Combine(abspath, Helpers.CheckFile)); var results = shreds.Select(shred => { var filename = Path.GetFileName(shred.Filepath); Assert.IsTrue(filename != null); Console.WriteLine("--------------------------------------"); Console.WriteLine("Shred Name" + Path.GetFileNameWithoutExtension(shred.Filepath)); Console.WriteLine("IsEmpty? = " + shred.IsEmpty); Console.WriteLine("Is Really Empty? = " + checker[filename]); Console.WriteLine("Correct: " + (checker[filename] == (shred.IsEmpty ? "y" : "n"))); Console.WriteLine(); return(checker[filename] == (shred.IsEmpty ? "y" : "n")); }); results.ToList().ForEach(Assert.IsTrue); }
public void NaiveKruskalPrimitive() { Shred.BUFFER = 0; Shred.SAMPLE_SIZE = 1; var folder = Path.Combine(Drive.GetDriveRoot(), Dir.NaiveKruskalTestDirectory); var paths = new List <string>(); paths.Add(Path.Combine(folder, NaiveThree)); paths.Add(Path.Combine(folder, NaiveSix)); paths.Add(Path.Combine(folder, NaiveTen)); foreach (var path in paths) { var shreds = Shred.Factory("Shred", path, false); var checker = Helpers.BuildChecker(Path.Combine(path, Helpers.CheckFile)); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); var indicies = results.Select((t, pos) => new Tuple <int, Shred>(pos, t)).ToList(); Console.WriteLine(" ---- " + path + "----"); var result = indicies.Select(pair => { var filename = Path.GetFileName(pair.Item2.Filepath); Assert.IsNotNull(filename); Assert.IsNotNull(checker[filename]); var expected = checker[filename]; var actual = pair.Item1; Console.WriteLine("Actual " + actual + " vs. " + expected + " | File: " + filename); return(actual.ToString(CultureInfo.InvariantCulture) == expected); }).ToList(); Exporter.ExportJson(results.First().Root()); Console.WriteLine(); result.ForEach(Assert.IsTrue); } }
/// <summary> /// Determines runs OCR and determines if a shred is empty or not /// </summary> /// <param name="shreds">A list of Shred Objects</param> public static void IsEmpty(Shred[] shreds) { // Get Images from Shreds Bitmap[] images = new Bitmap[shreds.Length]; for (int ii = 0; ii < shreds.Length; ii++) { images[ii] = new Bitmap(shreds[ii].Filepath); } // Run Fast Recognition OcrData[] datas = ParallelRecognize(images, images.Length, Accuracy.Low); for (int ii = 0; ii < datas.Length; ii++) { shreds[ii].AddOcrData(datas[ii]); } }
public static void DisplayTestShred() { //Create original Square Point[] patch1 = new Point[4]; patch1[0] = new Point(0, 0); patch1[1] = new Point(0, 10); patch1[2] = new Point(99, 10); patch1[3] = new Point(99, 0); Point[] patch2 = new Point[4]; patch2[0] = new Point(0, 50); patch2[1] = new Point(0, 60); patch2[2] = new Point(99, 60); patch2[3] = new Point(99, 50); // Create a Tester Square to compare Point[] patch3 = new Point[4]; patch3[0] = new Point(0, 110); patch3[1] = new Point(0, 120); patch3[2] = new Point(99, 120); patch3[3] = new Point(99, 110); Point[] patch4 = new Point[4]; patch4[0] = new Point(0, 160); patch4[1] = new Point(0, 170); patch4[2] = new Point(99, 170); patch4[3] = new Point(99, 160); // Create an Original Image var original = new Image <Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(patch1, new Bgr(Color.Gray)); original.FillConvexPoly(patch2, new Bgr(Color.Gray)); //Create Image to compare with var tester = new Image <Bgr, Byte>(100, 200, new Bgr(Color.HotPink)); tester.FillConvexPoly(patch3, new Bgr(Color.Gray)); tester.FillConvexPoly(patch4, new Bgr(Color.Gray)); //ImageViewer display = new ImageViewer(original, "TestBitmap"); //display.ShowDialog(); //ImageViewer display2 = new ImageViewer(tester, "Test Image"); //display2.ShowDialog(); const string filepath = "originalshrd.bmp"; const string filepath2 = "testshred.bmp"; if (File.Exists(filepath)) { File.Delete(filepath); } if (File.Exists(filepath2)) { File.Delete(filepath2); } original.ToBitmap().Save(filepath); tester.ToBitmap().Save(filepath2); Shred originalshred = new Shred(filepath); Shred testershred = new Shred(filepath2); originalshred.VisualizeLuminousity(Direction.FromLeft); originalshred.VisualizeThresholded(Direction.FromLeft); originalshred.VisualizeChamfers(Direction.FromLeft); testershred.VisualizeThresholded(Direction.FromLeft); testershred.VisualizeLuminousity(Direction.FromLeft); testershred.VisualizeChamfers(Direction.FromRight); }
public void ShredChamferSimilarityTest() { //Create original Square Point[] patch1 = new Point[4]; patch1[0] = new Point(0, 0); patch1[1] = new Point(0, 10); patch1[2] = new Point(99, 10); patch1[3] = new Point(99, 0); Point[] patch2 = new Point[4]; patch2[0] = new Point(0, 50); patch2[1] = new Point(0, 60); patch2[2] = new Point(99, 60); patch2[3] = new Point(99, 50); // Create a Tester Square to compare Point[] patch3 = new Point[4]; patch3[0] = new Point(0, 100); patch3[1] = new Point(0, 110); patch3[2] = new Point(99, 110); patch3[3] = new Point(99, 100); Point[] patch4 = new Point[4]; patch4[0] = new Point(0, 150); patch4[1] = new Point(0, 160); patch4[2] = new Point(99, 160); patch4[3] = new Point(99, 150); // Create an Original Image var original = new Image<Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(patch1, new Bgr(Color.Gray)); original.FillConvexPoly(patch2, new Bgr(Color.Gray)); //Create Image to compare with var tester = new Image<Bgr, Byte>(100, 200, new Bgr(Color.HotPink)); tester.FillConvexPoly(patch3, new Bgr(Color.Gray)); tester.FillConvexPoly(patch4, new Bgr(Color.Gray)); const string filepath = "originalshrd.bmp"; const string filepath2 = "testshred.bmp"; // Delete Shred Files if (File.Exists(filepath)) { File.Delete(filepath); } if (File.Exists(filepath2)) { File.Delete(filepath2); } // Save bitmaps to load as shreds original.ToBitmap().Save(filepath); tester.ToBitmap().Save(filepath2); // Create new shreds Shred originalshred = new Shred(filepath); Shred testershred = new Shred(filepath2); // Run Similarity test var actual = MatchData.CompareShred( originalshred, testershred, Direction.FromLeft, Orientation.Regular, Direction.FromRight, Orientation.Regular ).Offset; const int expected = 100; Assert.IsTrue(actual == expected); }
public void ShredSerializingTest() { // Create a Square Point[] patch1 = new Point[4]; patch1[0] = new Point(0, 0); patch1[1] = new Point(0, 10); patch1[2] = new Point(99, 10); patch1[3] = new Point(99, 0); Point[] patch2 = new Point[4]; patch2[0] = new Point(0, 50); patch2[1] = new Point(0, 60); patch2[2] = new Point(99, 60); patch2[3] = new Point(99, 50); // Create an Original Image var original = new Image<Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(patch1, new Bgr(Color.Gray)); original.FillConvexPoly(patch2, new Bgr(Color.Gray)); // Ensure filepaths are clear for writing files const string filepath = "shredtest.bmp"; const string serializedpath = "test.shred"; if (File.Exists(filepath)) { File.Delete(filepath); } original.ToBitmap().Save(filepath); Assert.IsTrue(File.Exists(filepath)); Shred myshred = new Shred(filepath); if (File.Exists(serializedpath)) { File.Delete(serializedpath); } // Save and load shred Assert.IsFalse(File.Exists(serializedpath)); Shred.Save(myshred, serializedpath); Assert.IsTrue(File.Exists(serializedpath)); Shred newshred = Shred.Load(serializedpath); Assert.IsTrue(newshred.Sparsity[(int) Direction.FromLeft] == myshred.Sparsity[(int) Direction.FromLeft]); }
public void ShredChamferSimilarityTest() { //Create original Square Point[] patch1 = new Point[4]; patch1[0] = new Point(0, 0); patch1[1] = new Point(0, 10); patch1[2] = new Point(99, 10); patch1[3] = new Point(99, 0); Point[] patch2 = new Point[4]; patch2[0] = new Point(0, 50); patch2[1] = new Point(0, 60); patch2[2] = new Point(99, 60); patch2[3] = new Point(99, 50); // Create a Tester Square to compare Point[] patch3 = new Point[4]; patch3[0] = new Point(0, 100); patch3[1] = new Point(0, 110); patch3[2] = new Point(99, 110); patch3[3] = new Point(99, 100); Point[] patch4 = new Point[4]; patch4[0] = new Point(0, 150); patch4[1] = new Point(0, 160); patch4[2] = new Point(99, 160); patch4[3] = new Point(99, 150); // Create an Original Image var original = new Image <Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(patch1, new Bgr(Color.Gray)); original.FillConvexPoly(patch2, new Bgr(Color.Gray)); //Create Image to compare with var tester = new Image <Bgr, Byte>(100, 200, new Bgr(Color.HotPink)); tester.FillConvexPoly(patch3, new Bgr(Color.Gray)); tester.FillConvexPoly(patch4, new Bgr(Color.Gray)); const string filepath = "originalshrd.bmp"; const string filepath2 = "testshred.bmp"; // Delete Shred Files if (File.Exists(filepath)) { File.Delete(filepath); } if (File.Exists(filepath2)) { File.Delete(filepath2); } // Save bitmaps to load as shreds original.ToBitmap().Save(filepath); tester.ToBitmap().Save(filepath2); // Create new shreds Shred originalshred = new Shred(filepath); Shred testershred = new Shred(filepath2); // Run Similarity test var actual = MatchData.CompareShred( originalshred, testershred, Direction.FromLeft, Orientation.Regular, Direction.FromRight, Orientation.Regular ).Offset; const int expected = 100; Assert.IsTrue(actual == expected); }
/// <summary> /// Given an array of shreds, /// we OCR them all and save results to the shred object /// </summary> /// <param name="shreds">Array of initialized shred objects</param> /// <param name="lang">Desired OCR langauge</param> public static void ShredOcr(Shred[] shreds, string lang = "eng") { Bitmap[] images = new Bitmap[shreds.Length]; Bitmap[] reversed = new Bitmap[shreds.Length]; int index = 0; foreach (Shred shred in shreds) { images[index] = new Bitmap(shred.Filepath); reversed[index] = Filter.Reverse(images[index]); index += 1; } Tuple<long, OcrData, OcrData>[] results = ParallelDetectOrientation(images, reversed, Accuracy.Low, lang); for (int ii = 0; ii < results.Length; ii++) { long confidence = results[ii].Item1; if (confidence > 0) { shreds[ii].AddOcrData(results[ii].Item2, Math.Abs(confidence), false); } else if (confidence <= 0) { shreds[ii].AddOcrData(results[ii].Item3, Math.Abs(confidence), true); } } }