Skip to content

Commit

Permalink
added settings for taming-multiplier. improved taming-calc-display. i…
Browse files Browse the repository at this point in the history
…mproved OCR for 1050.
  • Loading branch information
cadon committed Jul 2, 2016
1 parent e3c8b25 commit 5a55c95
Show file tree
Hide file tree
Showing 18 changed files with 1,009 additions and 727 deletions.
4 changes: 2 additions & 2 deletions ARKBreedingStats/ARKOverlay.Designer.cs

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

21 changes: 11 additions & 10 deletions ARKBreedingStats/ARKOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void inventoryCheckTimer_Tick(object sender, EventArgs e)
lblStatus.Text = "..";
Application.DoEvents();
OCRing = true;
if ( !ArkOCR.OCR.isDinoInventoryVisible() )
if (!ArkOCR.OCR.isDinoInventoryVisible())
{
for (int i = 0; i < labels.Count(); i++)
if ( labels[i] != null )
if (labels[i] != null)
labels[i].Text = "";
}
else
Expand All @@ -75,16 +75,16 @@ void inventoryCheckTimer_Tick(object sender, EventArgs e)

public void setValues(float[] wildValues, float[] tamedValues, Color[] colors = null)
{
foreach( KeyValuePair<String,Point> kv in ArkOCR.OCR.statPositions )
foreach (KeyValuePair<String, Point> kv in ArkOCR.OCR.statPositions)
{
if (kv.Key == "Torpor")
continue;

int statIndex = -1;
switch( kv.Key )
switch (kv.Key)
{
case "NameAndLevel": statIndex = 0; break;
case "Health": statIndex = 1; break;
case "Health": statIndex = 1; break;
case "Stamina": statIndex = 2; break;
case "Oxygen": statIndex = 3; break;
case "Food": statIndex = 4; break;
Expand All @@ -102,9 +102,9 @@ public void setValues(float[] wildValues, float[] tamedValues, Color[] colors =
if (tamedValues[statIndex] != 0)
labels[statIndex].Text += " + d" + tamedValues[statIndex];
labels[statIndex].Text += "]";
labels[statIndex].Location = this.PointToClient(ArkOCR.OCR.lastLetterositions[kv.Key]);
if (kv.Key != "NameAndLevel" )
labels[statIndex].Location = this.PointToClient(ArkOCR.OCR.lastLetterPositions[kv.Key]);

if (kv.Key != "NameAndLevel")
labels[statIndex].ForeColor = colors[statIndex];

lblStatus.Location = new Point(labels[0].Location.X - 100, 10);
Expand All @@ -115,7 +115,8 @@ public void setValues(float[] wildValues, float[] tamedValues, Color[] colors =

internal void setExtraText(string p)
{
Point loc = this.PointToClient(ArkOCR.OCR.lastLetterositions["NameAndLevel"]);
//Point loc = this.PointToClient(ArkOCR.OCR.lastLetterPositions["NameAndLevel"]);
Point loc = this.PointToClient(ArkOCR.OCR.statPositions["NameAndLevel"]);

loc.Offset(0, 30);

Expand Down Expand Up @@ -173,7 +174,7 @@ internal void setBreedingProgressValues(float percentage, int maxTime)
text += "\r\n[adult: " + ts.ToString(tsformat) + "]";

txtBreedingProgress.Text = text;
txtBreedingProgress.Location = this.PointToClient(ArkOCR.OCR.lastLetterositions["CurrentWeight"]);
txtBreedingProgress.Location = this.PointToClient(ArkOCR.OCR.lastLetterPositions["CurrentWeight"]);
}
}
}
148 changes: 80 additions & 68 deletions ARKBreedingStats/ArkOCR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ArkOCR
private static ArkOCR _OCR;
public static FlowLayoutPanel debugPanel { get; set; }
private int[] calibrationResolution = new int[] { 0, 0 };
public Dictionary<String, Point> lastLetterositions = new Dictionary<string, Point>();
public Dictionary<String, Point> lastLetterPositions = new Dictionary<string, Point>();
private bool coordsAfterDot = false;
public Process ARKProcess;
public int currentResolution = -1;
Expand Down Expand Up @@ -504,20 +504,30 @@ private static bool HasWhiteInVerticalLine(Bitmap source, int posXInImage)
if (posXInImage >= source.Width)
return false;

int greys = source.Height / 3;

for (int h = 0; h < source.Height; h++)
{
if (source.GetPixel(posXInImage, h).R == 255)
{
hasWhite = true;
break;
}
else if (source.GetPixel(posXInImage, h).R > 0)
{
greys--;
if (greys == 0)
{
hasWhite = true;
break;
}
}
}
return hasWhite;
}

private static Rectangle letterRect(Bitmap source, int hStart, int hEnd)
{

int startWhite = -1, endWhite = -1;
for (int j = 0; j < source.Height; j++)
{
Expand All @@ -528,7 +538,7 @@ private static Rectangle letterRect(Bitmap source, int hStart, int hEnd)
startWhite = j;
}

if (endWhite == -1 && source.GetPixel(i, (source.Height - j) - 1).R != 0)
if (endWhite == -1 && source.GetPixel(i, (source.Height - j) - 1).R == 255)
{
endWhite = (source.Height - j);
}
Expand Down Expand Up @@ -600,7 +610,7 @@ public float[] doOCR(out string OCRText, out string dinoName, string useImageFil
(statName == "Oxygen" || statName == "Imprinting"))
continue; // these can be missing, it's fine

lastLetterositions[statName] = new Point(statPositions[statName].X + lastLetterPosition(removePixelsUnderThreshold(GetGreyScale(testbmp), whiteThreshold)), statPositions[statName].Y);
lastLetterPositions[statName] = new Point(statPositions[statName].X + lastLetterPosition(removePixelsUnderThreshold(GetGreyScale(testbmp), whiteThreshold)), statPositions[statName].Y);

finishedText += "\r\n" + statName + ": " + statOCR;

Expand Down Expand Up @@ -704,82 +714,84 @@ private string readImage(int resolution, Bitmap source, bool onlyMaximalMatches,
{
// found a letter, see if a match can be found
Rectangle letterR = letterRect(cleanedImage, letterStart, letterEnd);

Bitmap testImage = SubImage(cleanedImage, letterR.Left, letterR.Top, letterR.Width, letterR.Height);
//testImage.Save("D:\\temp\\debug_letterfound.png");// TODO comment out
Dictionary<int, float> matches = new Dictionary<int, float>();
float bestMatch = 0;
for (int l = 0; l < theAlphabet.GetLength(1); l++)
if (letterR.Width > 0 && letterR.Height > 0)
{
float match = 0;
if (theAlphabet[resolution, l] != null)
match = (float)(PercentageMatch(theAlphabet[resolution, l], testImage) * charWeighting[l]);
else
continue;

if (match > 0.5)
Bitmap testImage = SubImage(cleanedImage, letterR.Left, letterR.Top, letterR.Width, letterR.Height);
//testImage.Save("D:\\temp\\debug_letterfound.png");// TODO comment out
Dictionary<int, float> matches = new Dictionary<int, float>();
float bestMatch = 0;
for (int l = 0; l < theAlphabet.GetLength(1); l++)
{
matches[l] = match;
if (bestMatch < match)
bestMatch = match;
float match = 0;
if (theAlphabet[resolution, l] != null)
match = (float)(PercentageMatch(theAlphabet[resolution, l], testImage) * charWeighting[l]);
else
continue;

if (match > 0.5)
{
matches[l] = match;
if (bestMatch < match)
bestMatch = match;
}
}
}

if (matches.Count == 0)
continue;
if (matches.Count == 0)
continue;

Dictionary<int, float> goodMatches = new Dictionary<int, float>();
Dictionary<int, float> goodMatches = new Dictionary<int, float>();

if (matches.Count == 1)
goodMatches = matches;
else
{
foreach (KeyValuePair<int, float> kv in matches)
if (kv.Value > 0.95 * bestMatch)
goodMatches[kv.Key] = kv.Value; // discard matches that are not at least 95% as good as the best match
}

//// debugging / TODO
//// save recognized image and two best matches with percentage
//Bitmap debugImg = new Bitmap(200, 50);
//using (Graphics g = Graphics.FromImage(debugImg))
//{
// g.FillRectangle(Brushes.DarkCyan, 0, 0, debugImg.Width, debugImg.Height);
// g.DrawImage(testImage, 1, 1, testImage.Width, testImage.Height);
// int i = testImage.Width + 25;
// Font font = new Font("Arial", 8);

// foreach (int l in goodMatches.Keys)
// {
// g.DrawImage(theAlphabet[resolution, l], i, 1, theAlphabet[resolution, l].Width, theAlphabet[resolution, l].Height);
// g.DrawString(Math.Round(goodMatches[l] * 100).ToString(), font, (bestMatch == goodMatches[l] ? Brushes.DarkGreen : Brushes.DarkRed), i, 35);
// i += theAlphabet[resolution, l].Width + 15;
// }
// debugImg.Save("D:\\temp\\debug_letter" + DateTime.Now.ToString("HHmmss\\-fffffff") + x + ".png");
//}
//// end debugging
if (matches.Count == 1)
goodMatches = matches;
else
{
foreach (KeyValuePair<int, float> kv in matches)
if (kv.Value > 0.95 * bestMatch)
goodMatches[kv.Key] = kv.Value; // discard matches that are not at least 95% as good as the best match
}

if (goodMatches.Count == 1)
result += (char)(goodMatches.Keys.ToArray()[0]);
else
{
if (onlyMaximalMatches)
//// debugging / TODO
//// save recognized image and two best matches with percentage
//Bitmap debugImg = new Bitmap(200, 50);
//using (Graphics g = Graphics.FromImage(debugImg))
//{
// g.FillRectangle(Brushes.DarkCyan, 0, 0, debugImg.Width, debugImg.Height);
// g.DrawImage(testImage, 1, 1, testImage.Width, testImage.Height);
// int i = testImage.Width + 25;
// Font font = new Font("Arial", 8);

// foreach (int l in goodMatches.Keys)
// {
// g.DrawImage(theAlphabet[resolution, l], i, 1, theAlphabet[resolution, l].Width, theAlphabet[resolution, l].Height);
// g.DrawString(Math.Round(goodMatches[l] * 100).ToString(), font, (bestMatch == goodMatches[l] ? Brushes.DarkGreen : Brushes.DarkRed), i, 35);
// i += theAlphabet[resolution, l].Width + 15;
// }
// debugImg.Save("D:\\temp\\debug_letter" + DateTime.Now.ToString("HHmmss\\-fffffff\\-") + x + ".png");
//}
//// end debugging

if (goodMatches.Count == 1)
result += (char)(goodMatches.Keys.ToArray()[0]);
else
{
foreach (int l in goodMatches.Keys)
if (onlyMaximalMatches)
{
if (goodMatches[l] == bestMatch)
foreach (int l in goodMatches.Keys)
{
result += (char)l;
break; // if there are multiple best matches take only the first
if (goodMatches[l] == bestMatch)
{
result += (char)l;
break; // if there are multiple best matches take only the first
}
}
}
}
else
{
result += "[";
foreach (int l in goodMatches.Keys)
result += (char)l + goodMatches[l].ToString("{0.00}") + " ";
result += "]";
else
{
result += "[";
foreach (int l in goodMatches.Keys)
result += (char)l + goodMatches[l].ToString("{0.00}") + " ";
result += "]";
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions ARKBreedingStats/CreatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace ARKBreedingStats
public int maxWildLevel = 150;
public int maxBreedingSuggestions = 10;
public double imprintingMultiplier = 1;
public double tamingSpeedMultiplier = 1;
public double tamingFoodRateMultiplier = 1;
[XmlArray]
public List<Player> players = new List<Player>();
[XmlArray]
Expand Down
11 changes: 11 additions & 0 deletions ARKBreedingStats/Extraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace ARKBreedingStats
{
class Extraction
{
private static Extraction _extraction;
public List<StatResult>[] results = new List<StatResult>[8]; // stores the possible results of all stats as array (wildlevel, domlevel, tamingEff)
public int[] chosenResults = new int[8];
public bool[] fixedResults = new bool[8];
Expand All @@ -30,6 +31,16 @@ public Extraction()
}
}

public static Extraction E
{
get
{
if (_extraction == null)
_extraction = new Extraction();
return _extraction;
}
}

public void Clear()
{
for (int s = 0; s < 8; s++)
Expand Down
Loading

0 comments on commit 5a55c95

Please sign in to comment.