Skip to content

Commit

Permalink
--find 追加
Browse files Browse the repository at this point in the history
  • Loading branch information
y9o committed Feb 6, 2020
1 parent e8c299f commit 37cfa8f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
61 changes: 54 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct textLine
}
class Options
{

[Option("head", Required = false, Default = 2, HelpText = "前方ファイル数")]
public int Head { get; set; }

Expand All @@ -31,8 +32,12 @@ class Options
[Option('V', "view", Required = false, HelpText = "OCR結果を表示")]
public bool ViewOCR { get; set; }

[Option('f', "find", Required = false, HelpText = "検索文字列 ,区切りでOR検索")]
public string Find { get; set; }

[Option('s', "stop", Required = false, HelpText = "ISBNを見つけたら残り画像は無視する")]
public bool Skip { get; set; }

[Option("noRotate", Required = false, HelpText = "270度回転して再OCRをしない")]
public bool noRotate { get; set; }
[Option("noBinarize", Required = false, HelpText = "2値化して再OCRをしない")]
Expand Down Expand Up @@ -168,7 +173,7 @@ static void scanFolder(Options _op)
}
}
}
else if(System.IO.File.Exists(op.Input))
else if (System.IO.File.Exists(op.Input))
{
Console.Write("Scan: {0}\n", op.Input);
try
Expand Down Expand Up @@ -212,7 +217,7 @@ static void scanFolder(Options _op)
else
{
isbnMap[isbn.ISBN13] = isbn.Rank;
}
}
}
//ランクが高いISBNを一つ選択する
{
Expand All @@ -238,22 +243,30 @@ static void scanFolder(Options _op)
}
}
}

static async Task<List<ISBN>> scanFromImage(string image, OcrEngine engine)
{
var isbns = new List<ISBN>();
image = System.IO.Path.GetFullPath(image);
var file = await StorageFile.GetFileFromPathAsync(image);
var ret = "";
using (var stream = await file.OpenReadAsync())
{
var decoder = await BitmapDecoder.CreateAsync(stream);
using (var bmp = await decoder.GetSoftwareBitmapAsync())
{
var r = await ocrFromBMP(bmp, engine);
if (op.ViewOCR)
bool printflag = false;
if (op.ViewOCR || findStr(r.Original))
{
printflag = true;
Console.WriteLine(r.Original);
}
else if (findStr(r.Custom))
{
printflag = true;
Console.WriteLine(r.Custom);
}

var n = findISBN(r);
if (n.Count > 0)
{
Expand All @@ -266,11 +279,18 @@ static async Task<List<ISBN>> scanFromImage(string image, OcrEngine engine)
using (var rotateBmp = Bitmap.Rotate270(bmp))
{
r = await ocrFromBMP(rotateBmp, engine);
if (op.ViewOCR)
if (op.ViewOCR || (printflag == false && findStr(r.Original)))
{
printflag = true;
Console.WriteLine("==Rotate270==========");
Console.WriteLine(r.Original);
}
else if (printflag == false && findStr(r.Custom))
{
printflag = true;
Console.WriteLine("==Rotate270==========");
Console.WriteLine(r.Custom);
}
n = findISBN(r);
if (n.Count > 0)
{
Expand All @@ -283,11 +303,18 @@ static async Task<List<ISBN>> scanFromImage(string image, OcrEngine engine)
using (var otsu = Bitmap.Binarize(bmp))
{
r = await ocrFromBMP(otsu, engine);
if (op.ViewOCR)
if (op.ViewOCR || (printflag == false && findStr(r.Original)))
{
printflag = true;
Console.WriteLine("==Binarize ==========");
Console.WriteLine(r.Original);
}
else if (printflag == false && findStr(r.Custom))
{
printflag = true;
Console.WriteLine("==Binarize ==========");
Console.WriteLine(r.Custom);
}
n = findISBN(r);
if (n.Count > 0)
{
Expand All @@ -300,11 +327,16 @@ static async Task<List<ISBN>> scanFromImage(string image, OcrEngine engine)
using (var rotateBmp2 = Bitmap.Rotate270(otsu))
{
r = await ocrFromBMP(rotateBmp2, engine);
if (op.ViewOCR)
if (op.ViewOCR || (printflag == false && findStr(r.Original)))
{
Console.WriteLine("==Binarize270========");
Console.WriteLine(r.Original);
}
else if (printflag == false && findStr(r.Custom))
{
Console.WriteLine("==Binarize270========");
Console.WriteLine(r.Custom);
}
n = findISBN(r);
if (n.Count > 0)
{
Expand Down Expand Up @@ -472,6 +504,21 @@ static ISBN isISBN(string txt)
}
return null;
}

static public bool findStr(string txt)
{
if (op.Find == null || op.Find == "")
return false;
foreach (var str in op.Find.Split(','))
{
if (txt.IndexOf(str) >= 0)
{
return true;
}
}
return false;
}

}

}
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.3")]
[assembly: AssemblyFileVersion("0.0.0.3")]
[assembly: AssemblyVersion("0.0.0.4")]
[assembly: AssemblyFileVersion("0.0.0.4")]

0 comments on commit 37cfa8f

Please sign in to comment.