Skip to content

Commit

Permalink
added preview of white-threshold if value is changed in the OCR and a…
Browse files Browse the repository at this point in the history
… screenshot is set. fixed critical extractor-bug.
  • Loading branch information
cadaei committed Apr 9, 2018
1 parent c74979a commit 27edec4
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 42 deletions.
4 changes: 2 additions & 2 deletions ARKBreedingStats/Extraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public bool setStatLevelBoundsAndFilter(out int statError)
bool resultsRemoved1 = (oldResultCount != results[statsWithTE[es]].Count);
if (resultsRemoved1)
{
filterBoundsAndTEAgain = adjustBoundsToStatResults(es);
filterBoundsAndTEAgain = adjustBoundsToStatResults(statsWithTE[es]);
}

List<StatResult> validResults2 = new List<StatResult>();
Expand All @@ -513,7 +513,7 @@ public bool setStatLevelBoundsAndFilter(out int statError)
bool resultsRemoved2 = (oldResultCount != results[statsWithTE[et]].Count);
if (resultsRemoved2)
{
filterBoundsAndTEAgain = adjustBoundsToStatResults(et) || filterBoundsAndTEAgain;
filterBoundsAndTEAgain = adjustBoundsToStatResults(statsWithTE[et]) || filterBoundsAndTEAgain;
}

if ((resultsRemoved1 || resultsRemoved2) && et > 1)
Expand Down
8 changes: 4 additions & 4 deletions ARKBreedingStats/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ARKBreedingStats/ImportExported.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ static public CreatureValues importExportedCreature(string filePath)
cv.imprinterName = text;
if (string.IsNullOrEmpty(cv.owner))
cv.owner = text;
if (!String.IsNullOrWhiteSpace(text))
cv.isBred = true; // TODO is this a correct assumption?
break;
// todo mutations for mother and father
case "RandomMutationsMale":
Expand Down Expand Up @@ -154,6 +156,7 @@ static public CreatureValues importExportedCreature(string filePath)
{
cv.motherGuid = builtGuid(m.Groups[5].Value, m.Groups[6].Value);
cv.fatherGuid = builtGuid(m.Groups[2].Value, m.Groups[3].Value);
cv.isBred = true;
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("0.27.2")]
[assembly: AssemblyFileVersion("0.27.3")]
2 changes: 1 addition & 1 deletion ARKBreedingStats/SpeciesSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class SpeciesSelector : UserControl
private List<string> lastSpecies;
private List<string> iconIndices;
public int keepNrLastSpecies;
CancellationTokenSource cancelSource;
private CancellationTokenSource cancelSource;

public SpeciesSelector()
{
Expand Down
12 changes: 6 additions & 6 deletions ARKBreedingStats/ocr/ArkOCR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Bitmap SubImage(Bitmap source, int x, int y, int width, int height)
return target;
}

public Bitmap GetGreyScale(Bitmap source, bool writingInWhite = false)
public static Bitmap GetGreyScale(Bitmap source, bool writingInWhite = false)
{
Bitmap dest = (Bitmap)source.Clone();

Expand Down Expand Up @@ -158,12 +158,12 @@ public Bitmap GetGreyScale(Bitmap source, bool writingInWhite = false)
int sum = rgbValues[idx] + rgbValues[idx + 1] + rgbValues[idx + 2];

//grey = Math.Max(Math.Max(rgbValues[idx], rgbValues[idx + 1]), rgbValues[idx + 2]);
grey = Math.Max(rgbValues[idx], rgbValues[idx + 1]); // ignoring the blue-channel, ui is bluish
grey = Math.Max(rgbValues[idx], rgbValues[idx + 1]); // ignoring the blue-channel, ui is blueish
}
else
{
//int sum = rgbValues[idx] + rgbValues[idx + 1] + rgbValues[idx + 2];
int sum = rgbValues[idx] + rgbValues[idx + 1]; // ignoring the blue-channel, ui is bluish
int sum = rgbValues[idx] + rgbValues[idx + 1]; // ignoring the blue-channel, ui is blueish

grey = (byte)(sum / 2);
}
Expand All @@ -183,7 +183,7 @@ public Bitmap GetGreyScale(Bitmap source, bool writingInWhite = false)
return dest;
}

public Bitmap removePixelsUnderThreshold(Bitmap source, int threshold)
public static Bitmap removePixelsUnderThreshold(Bitmap source, int threshold, bool disposeSource = false)
{
Bitmap dest = (Bitmap)source.Clone();

Expand Down Expand Up @@ -256,7 +256,7 @@ public Bitmap removePixelsUnderThreshold(Bitmap source, int threshold)
Marshal.Copy(rgbValues, 0, ptr, numBytes);

dest.UnlockBits(bmpData);

if (disposeSource) source.Dispose();
return dest;
}

Expand Down Expand Up @@ -1015,7 +1015,7 @@ public bool isDinoInventoryVisible()
ScreenCaptureProcess = p[0];
else return false;
}

Bitmap screenshotbmp = null;// = (Bitmap)Bitmap.FromFile(@"D:\ScreenshotsArk\Clipboard12.png");

if (Win32Stuff.GetForegroundWindow() != ScreenCaptureProcess.MainWindowHandle)
Expand Down
6 changes: 4 additions & 2 deletions ARKBreedingStats/ocr/OCRControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 66 additions & 25 deletions ARKBreedingStats/ocr/OCRControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace ARKBreedingStats.ocr
{
Expand All @@ -23,6 +24,7 @@ public partial class OCRControl : UserControl
private List<int> recognizedFontSizes;
private Bitmap screenshot;
private bool updateDrawing, ignoreValueChange;
private CancellationTokenSource cancelSource;

public OCRControl()
{
Expand Down Expand Up @@ -51,6 +53,34 @@ public void initLabelEntries()
private void nudWhiteTreshold_ValueChanged(object sender, EventArgs e)
{
updateWhiteThreshold?.Invoke((int)nudWhiteTreshold.Value);
showPreviewWhiteThreshold((int)nudWhiteTreshold.Value);
}

private void nudWhiteTreshold_Leave(object sender, EventArgs e)
{
showPreviewWhiteThreshold(-1);
}

/// <summary>
/// Shows a preview of the white-threshold if a screenshot is displayed
/// </summary>
/// <param name="value">The white-threshold. -1 disables the preview</param>
private async void showPreviewWhiteThreshold(int value)
{
cancelSource?.Cancel();
try
{
using (cancelSource = new CancellationTokenSource())
{
await Task.Delay(400, cancelSource.Token); // update preview only each interval
redrawScreenshot(-1, false, value);
}
}
catch (TaskCanceledException)
{
return;
}
cancelSource = null;
}

private void OCRDebugLayoutPanel_DragEnter(object sender, DragEventArgs e)
Expand Down Expand Up @@ -185,7 +215,7 @@ private void listBoxLabelRectangles_SelectedIndexChanged(object sender, EventArg
if (i >= 0)
{
setLabelControls(i);
redrawLabelRectangles(i);
redrawScreenshot(i);
}
}

Expand All @@ -205,40 +235,51 @@ private void setLabelControls(int rectangleIndex)
}
}

private void redrawLabelRectangles(int hightlightIndex)
/// <summary>
/// Redraws the screenshot
/// </summary>
/// <param name="hightlightIndex">which of the labels should be highlighted</param>
/// <param name="showLabels">show labels</param>
/// <param name="whiteThreshold">preview of white-Threshold. -1 to disable</param>
private void redrawScreenshot(int hightlightIndex, bool showLabels = true, int whiteThreshold = -1)
{
if (OCRDebugLayoutPanel.Controls.Count > 0 && OCRDebugLayoutPanel.Controls[OCRDebugLayoutPanel.Controls.Count - 1] is PictureBox && screenshot != null)
{
PictureBox p = (PictureBox)OCRDebugLayoutPanel.Controls[OCRDebugLayoutPanel.Controls.Count - 1];
Bitmap b = new Bitmap(screenshot);
Bitmap b = new Bitmap((whiteThreshold >= 0 ? ArkOCR.removePixelsUnderThreshold(ArkOCR.GetGreyScale(screenshot), whiteThreshold, true) : screenshot));
using (Graphics g = Graphics.FromImage(b))
using (Pen penW = new Pen(Color.White, 2))
using (Pen penY = new Pen(Color.Yellow, 2))
using (Pen penB = new Pen(Color.Black, 2))
{
penW.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
penY.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
penB.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
for (int r = 0; r < ArkOCR.OCR.ocrConfig.labelRectangles.Count; r++)
if (showLabels)
{
Rectangle rec = ArkOCR.OCR.ocrConfig.labelRectangles[r];
if (r == hightlightIndex)
{
rec.Inflate(2, 2);
g.DrawRectangle(penY, rec);
rec.Inflate(2, 2);
g.DrawRectangle(penB, rec);
}
else
using (Pen penW = new Pen(Color.White, 2))
using (Pen penY = new Pen(Color.Yellow, 2))
using (Pen penB = new Pen(Color.Black, 2))
{
rec.Inflate(2, 2);
g.DrawRectangle(penW, rec);
rec.Inflate(2, 2);
g.DrawRectangle(penB, rec);
penW.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
penY.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
penB.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
for (int r = 0; r < ArkOCR.OCR.ocrConfig.labelRectangles.Count; r++)
{
Rectangle rec = ArkOCR.OCR.ocrConfig.labelRectangles[r];
if (r == hightlightIndex)
{
rec.Inflate(2, 2);
g.DrawRectangle(penY, rec);
rec.Inflate(2, 2);
g.DrawRectangle(penB, rec);
}
else
{
rec.Inflate(2, 2);
g.DrawRectangle(penW, rec);
rec.Inflate(2, 2);
g.DrawRectangle(penB, rec);
}
}
}
}
}
Bitmap disp = (Bitmap)p.Image;
Bitmap disp = (Bitmap)p.Image; // take pointer to old image to dispose it soon
p.Image = b;
if (disp != null && disp != screenshot)
disp.Dispose();
Expand Down Expand Up @@ -320,7 +361,7 @@ private void updateRectangle()
ArkOCR.OCR.ocrConfig.labelRectangles[s] = new Rectangle((int)nudX.Value, ArkOCR.OCR.ocrConfig.labelRectangles[s].Y, (int)nudWidth.Value, (int)nudHeight.Value);
}
ArkOCR.OCR.ocrConfig.labelRectangles[i] = new Rectangle((int)nudX.Value, (int)nudY.Value, (int)nudWidth.Value, (int)nudHeight.Value);
redrawLabelRectangles(i);
redrawScreenshot(i);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
279.234.1,0.27.2
279.234.1,0.27.3

0 comments on commit 27edec4

Please sign in to comment.