Added laptime recognition (not precise enough yet tho)
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -15,7 +16,80 @@ namespace OCR_Decode
|
||||
}
|
||||
public override object DecodePng()
|
||||
{
|
||||
return 0;
|
||||
int result = GetTimeFromPng();
|
||||
return result;
|
||||
}
|
||||
private int GetTimeFromPng()
|
||||
{
|
||||
//returns milliseconds
|
||||
string rawResult = "";
|
||||
int treshold = 185;
|
||||
int result = 0;
|
||||
|
||||
Bitmap rawData = WindowImage;
|
||||
rawData = Window.ConvertToBlackAndWhite(rawData, treshold);
|
||||
|
||||
TesseractEngine engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
||||
|
||||
Page page = engine.Process(tessImage);
|
||||
Graphics g = Graphics.FromImage(rawData);
|
||||
// Get the iterator for the page layout
|
||||
using (var iter = page.GetIterator())
|
||||
{
|
||||
// Loop over the elements of the page layout
|
||||
iter.Begin();
|
||||
do
|
||||
{
|
||||
Rect boundingBox;
|
||||
// Get the bounding box for the current element
|
||||
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||
{
|
||||
g.DrawRectangle(Pens.Red, new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height));
|
||||
}
|
||||
// Get the text for the current element
|
||||
try{
|
||||
rawResult += iter.GetText(PageIteratorLevel.Word);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//nothing we just dont add it if its not a number
|
||||
}
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
|
||||
string[] rawNumbers;
|
||||
|
||||
rawNumbers = rawResult.Split('.',':');
|
||||
|
||||
if (rawNumbers.Length == 3)
|
||||
{
|
||||
//mm:ss:ms
|
||||
result = (Convert.ToInt32(rawNumbers[0]) * 1000 * 60) + (Convert.ToInt32(rawNumbers[1]) * 1000) + Convert.ToInt32(rawNumbers[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rawNumbers.Length == 2)
|
||||
{
|
||||
//ss:ms
|
||||
result = (Convert.ToInt32(rawNumbers[0]) * 1000) + Convert.ToInt32(rawNumbers[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rawNumbers.Length == 1)
|
||||
{
|
||||
//ss
|
||||
result = Convert.ToInt32(rawNumbers[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Auuuugh
|
||||
result = 1111111111;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,40 +15,6 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Name";
|
||||
}
|
||||
/*
|
||||
public override object DecodePng()
|
||||
{
|
||||
string result = "";
|
||||
|
||||
Bitmap rawData = WindowImage;
|
||||
rawData = Window.ConvertToBlackAndWhite(rawData,150);
|
||||
|
||||
TesseractEngine engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
||||
|
||||
Page page = engine.Process(tessImage);
|
||||
Graphics g = Graphics.FromImage(rawData);
|
||||
// Get the iterator for the page layout
|
||||
using (var iter = page.GetIterator())
|
||||
{
|
||||
// Loop over the elements of the page layout
|
||||
iter.Begin();
|
||||
do
|
||||
{
|
||||
Rect boundingBox;
|
||||
// Get the bounding box for the current element
|
||||
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||
{
|
||||
g.DrawRectangle(Pens.Red, new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height));
|
||||
}
|
||||
// Get the text for the current element
|
||||
result += iter.GetText(PageIteratorLevel.Word);
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
rawData.Save(Reader.DEBUG_DUMP_FOLDER + result + "_Before" + ".png");
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
public override object DecodePng(List<string> DriverList)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
Generated
+7
-7
@@ -40,23 +40,23 @@
|
||||
//
|
||||
this.pbxImage.Location = new System.Drawing.Point(12, 12);
|
||||
this.pbxImage.Name = "pbxImage";
|
||||
this.pbxImage.Size = new System.Drawing.Size(1000, 600);
|
||||
this.pbxImage.Size = new System.Drawing.Size(1231, 724);
|
||||
this.pbxImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.pbxImage.TabIndex = 0;
|
||||
this.pbxImage.TabStop = false;
|
||||
//
|
||||
// tbxResult
|
||||
//
|
||||
this.tbxResult.Location = new System.Drawing.Point(441, 618);
|
||||
this.tbxResult.Location = new System.Drawing.Point(719, 742);
|
||||
this.tbxResult.Multiline = true;
|
||||
this.tbxResult.Name = "tbxResult";
|
||||
this.tbxResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.tbxResult.Size = new System.Drawing.Size(571, 192);
|
||||
this.tbxResult.Size = new System.Drawing.Size(571, 255);
|
||||
this.tbxResult.TabIndex = 1;
|
||||
//
|
||||
// btnPrevious
|
||||
//
|
||||
this.btnPrevious.Location = new System.Drawing.Point(12, 618);
|
||||
this.btnPrevious.Location = new System.Drawing.Point(12, 745);
|
||||
this.btnPrevious.Name = "btnPrevious";
|
||||
this.btnPrevious.Size = new System.Drawing.Size(228, 72);
|
||||
this.btnPrevious.TabIndex = 2;
|
||||
@@ -65,7 +65,7 @@
|
||||
//
|
||||
// btnNext
|
||||
//
|
||||
this.btnNext.Location = new System.Drawing.Point(12, 696);
|
||||
this.btnNext.Location = new System.Drawing.Point(12, 823);
|
||||
this.btnNext.Name = "btnNext";
|
||||
this.btnNext.Size = new System.Drawing.Size(228, 72);
|
||||
this.btnNext.TabIndex = 3;
|
||||
@@ -75,7 +75,7 @@
|
||||
// lblFileName
|
||||
//
|
||||
this.lblFileName.AutoSize = true;
|
||||
this.lblFileName.Location = new System.Drawing.Point(12, 771);
|
||||
this.lblFileName.Location = new System.Drawing.Point(12, 898);
|
||||
this.lblFileName.Name = "lblFileName";
|
||||
this.lblFileName.Size = new System.Drawing.Size(66, 16);
|
||||
this.lblFileName.TabIndex = 4;
|
||||
@@ -85,7 +85,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1022, 822);
|
||||
this.ClientSize = new System.Drawing.Size(1255, 1009);
|
||||
this.Controls.Add(this.lblFileName);
|
||||
this.Controls.Add(this.btnNext);
|
||||
this.Controls.Add(this.btnPrevious);
|
||||
|
||||
@@ -247,8 +247,9 @@ namespace OCR_Decode
|
||||
}
|
||||
public static string ConvertMsToTime(int amountOfMs)
|
||||
{
|
||||
int minuts = Convert.ToInt32((float)amountOfMs / 1000f / 60f);
|
||||
int seconds = Convert.ToInt32((float)minuts * 60f - (float)amountOfMs / 1000f);
|
||||
//Convert.ToInt32 would round upand I dont want that
|
||||
int minuts = (int)((float)amountOfMs / (1000f * 60f));
|
||||
int seconds = (int)((amountOfMs - (minuts*60f*1000f))/1000);
|
||||
int ms = amountOfMs - ((minuts * 60 * 1000) + (seconds * 1000));
|
||||
|
||||
return minuts + ":" + seconds + ":" + ms;
|
||||
|
||||
Reference in New Issue
Block a user