-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathListImgsave.linq
72 lines (58 loc) · 2.08 KB
/
ListImgsave.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<Query Kind="Program">
<Namespace>System.Drawing</Namespace>
</Query>
readonly string PATH = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath), "imgsave");
readonly string PATH_CD = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath), "NumberRecognition", "counterdata");
readonly string PATH_TD = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath), "NumberRecognition", "testdata");
void Main()
{
new Hyperlinq(() =>
{
Directory
.EnumerateFiles(PATH)
.Select(p => new{Source = p, Target = Path.Combine(PATH_CD, Path.GetFileName(p)) , Image = Image.FromFile(p)})
.Where(p => p.Image.Width/p.Image.Height > 2.0)
.ToList()
.ForEach(p => File.Copy(p.Source, p.Target));
"SUCESS".Dump();
}, "[Copy counterdata]").Dump();
"".Dump();
new Hyperlinq(() =>
{
Directory
.EnumerateFiles(PATH_TD)
.ToList()
.ForEach(p => File.Delete(p));
Directory
.EnumerateFiles(PATH)
.Select(p => new{Source = p, Target = Path.Combine(PATH_TD, Path.GetFileName(p)) , Image = Image.FromFile(p)})
.Where(p => p.Image.Width/p.Image.Height < 2.0)
.ToList()
.ForEach(p => File.Copy(p.Source, p.Target));
"SUCESS".Dump();
}, "[Copy testdata]").Dump();
"".Dump();
//################################################################################
Directory
.EnumerateFiles(PATH)
.Where(p => Path.GetFileName(p).EndsWith(".png"))
.Select(p => Path.GetFileNameWithoutExtension(p))
.GroupBy(p => Regex.Match(p, @"(.*)_[0-9]*").Groups[1].Value)
.Select(p => new{Value = p.Key, Count = p.Count()})
.OrderBy(p => GOV(p.Value))
.Dump();
Directory
.EnumerateFiles(PATH)
.Where(p => Path.GetFileName(p).EndsWith(".png"))
.Select(p => new{Value = Regex.Match(Path.GetFileNameWithoutExtension(p), @"(.*)_[0-9]*").Groups[1].Value, Image = Image.FromFile(p)})
.Where(p => p.Image.Width/p.Image.Height > 2.0)
.OrderBy(p => GOV(p.Value))
.Dump();
}
int GOV(string s)
{
if (s.Length == 0) return 0;
string n = Regex.Replace(s, @"[^0-9]", "");
if (n.Length == 0) return 512;
return int.Parse(n) + ((s==n) ? (0) : (s[0] * 512));
}