commit 07ec658fd3d12d7affae1d4e78b66ca89668b0f1
parent 45a2ad4060d9b717c5ad0ea68a94131c58dfb9ee
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Thu, 27 Aug 2015 12:59:01 +0200
ADd example application.
Searches for image duplicates in directory.
Diffstat:
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/examples/test.d b/examples/test.d
@@ -0,0 +1,39 @@
+import puzzle;
+import std.stdio;
+import std.file;
+import std.conv;
+import std.parallelism;
+import std.algorithm;
+import std.range;
+import std.getopt;
+
+static bool isImage(string name){
+ return name.endsWith("jpg","JPG","png","PNG","gif","GIF")!=0;
+}
+
+void main(string args[]){
+ SpanMode m=SpanMode.shallow;
+ double threshold=0.55;
+
+ if(args.length<3){
+ writeln("Usage: ", args[0], " <[-r|--recursive]> <[--threshold,-t] double> <File> <Directory>");
+ return;
+ }
+
+ getopt(args,
+ "recursive|r", (){m=SpanMode.breadth;},
+ "threshold|t", &threshold);
+
+ Puzzle p;
+ p.initialize();
+ CVec cva=p.cvec();
+ cva.load(args[1]);
+ auto cvb=taskPool.workerLocalStorage(p.cvec());
+ foreach(ref name; parallel(dirEntries(args[2], m, false).filter!(a=>isImage(a)).array)){
+ try{cvb.get.load(name);}catch(PuzzleException e){continue;}
+
+ if(cva.compare(cvb.get)<threshold){
+ writeln(name);
+ }
+ }
+}