Now the tires windows can be focused on the important part
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -16,11 +17,94 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testTyres" + rnd.Next(0, 1000) + ".png");
|
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testTyres" + rnd.Next(0, 1000) + ".png");
|
||||||
|
|
||||||
|
return GetTyreInfos();
|
||||||
return new Tyre(Tyre.Type.Undefined, 0);
|
|
||||||
}
|
}
|
||||||
|
private Tyre GetTyreInfos()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
Bitmap rawData = WindowImage;
|
||||||
|
//Hards softs mediums Inter Wet -> HSMIW
|
||||||
|
Engine.SetVariable("tessedit_char_whitelist", "0123456789HSMIW");
|
||||||
|
Page page = Engine.Process(rawData);
|
||||||
|
Rectangle TyreRadius = new Rectangle(0, 0, 0, 0);
|
||||||
|
|
||||||
|
using (var iter = page.GetIterator())
|
||||||
|
{
|
||||||
|
iter.Begin();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Rect boundingBox;
|
||||||
|
|
||||||
|
// Get the bounding box for the current element
|
||||||
|
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||||
|
{
|
||||||
|
int xOffset = ((boundingBox.Width / 100) * 20) / 2;
|
||||||
|
int yOffset = ((boundingBox.Height / 100) * 20) / 2;
|
||||||
|
using (Graphics g = Graphics.FromImage(WindowImage))
|
||||||
|
{
|
||||||
|
//TyreRadius = new Rectangle(boundingBox.X1 - xOffset, boundingBox.Y1 - yOffset, boundingBox.Width + xOffset * 2, boundingBox.Height + yOffset * 2);
|
||||||
|
TyreRadius = new Rectangle(boundingBox.X1,boundingBox.Y1,boundingBox.Width,boundingBox.Height);
|
||||||
|
g.DrawRectangle(Pens.AliceBlue,TyreRadius);
|
||||||
|
GetSmallBitmapFromBigOne(WindowImage,TyreRadius).Save(Reader.DEBUG_DUMP_FOLDER + "Tyres" + result + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
result += iter.GetText(PageIteratorLevel.Word);
|
||||||
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
|
}
|
||||||
|
|
||||||
|
//rawData.Save(Reader.DEBUG_DUMP_FOLDER + "Tyres" + result + ".png");
|
||||||
|
|
||||||
|
page.Dispose();
|
||||||
|
*/
|
||||||
|
|
||||||
|
GetSmallBitmapFromBigOne(WindowImage,FindTyreZone()).Save(Reader.DEBUG_DUMP_FOLDER + "Tyres" + rnd.Next(0,1000) + ".png");
|
||||||
|
|
||||||
|
|
||||||
|
return new Tyre(Tyre.Type.Undefined,0);
|
||||||
|
}
|
||||||
|
private Rectangle FindTyreZone()
|
||||||
|
{
|
||||||
|
Bitmap bmp = WindowImage;
|
||||||
|
int currentPosition = bmp.Width;
|
||||||
|
int height = bmp.Height / 2;
|
||||||
|
Color limitColor = Color.FromArgb(0x50,0x50,0x50);
|
||||||
|
Color currentColor = Color.FromArgb(0,0,0);
|
||||||
|
|
||||||
|
Size newWindowSize = new Size(bmp.Height,bmp.Height);
|
||||||
|
|
||||||
|
while(currentColor.R <= limitColor.R && currentColor.G <= limitColor.G && currentColor.B <= limitColor.B && currentPosition > 0)
|
||||||
|
{
|
||||||
|
currentPosition--;
|
||||||
|
currentColor = bmp.GetPixel(currentPosition,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Its here to let the new window include a little bit of the right side
|
||||||
|
int offset = Convert.ToInt32((float)newWindowSize.Width / 100f * 20f);
|
||||||
|
int CorrectedX = currentPosition - (newWindowSize.Width - offset);
|
||||||
|
if (CorrectedX <= 0)
|
||||||
|
return new Rectangle(0,0,newWindowSize.Width,newWindowSize.Height);
|
||||||
|
|
||||||
|
return new Rectangle(CorrectedX,0,newWindowSize.Width,newWindowSize.Height);
|
||||||
|
}
|
||||||
|
private Bitmap GetSmallBitmapFromBigOne(Bitmap bmp, Rectangle rectangle)
|
||||||
|
{
|
||||||
|
Bitmap sample = new Bitmap(rectangle.Width, rectangle.Height);
|
||||||
|
Graphics g = Graphics.FromImage(sample);
|
||||||
|
g.DrawImage(bmp, new Rectangle(0, 0, sample.Width, sample.Height), rectangle, GraphicsUnit.Pixel);
|
||||||
|
return sample;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public Tyre.Type GetColor(Bitmap bmp)
|
||||||
|
{
|
||||||
|
return Color.Violet;
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
struct Tyre
|
struct Tyre
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user