Skip to content

Commit b5fccb2

Browse files
committed
fix: read stack numbers
1 parent 9b9691d commit b5fccb2

File tree

5 files changed

+44
-51
lines changed

5 files changed

+44
-51
lines changed

osrs/interfaces/mainscreen/bank.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ begin
121121
Self.Title.Setup(Self.Bounds);
122122

123123
Self.Tabs := TBoxArray.Create(Self.Bounds.TopLeft.Offset(47, 42), 10, 1, 35, 28, [5, 0]);
124-
//Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]);
124+
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]);
125125

126126
Self.SlotsArea.X1 := Self.Bounds.X1 + 57;
127127
Self.SlotsArea.Y1 := Self.Bounds.Y1 + 77;

osrs/interfaces/setup.simba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ begin
2020
RSInterface.SetupInterface();
2121
XPBar.SetupInterface();
2222
Prayer.SetupInterface();
23+
Stats.SetupInterface();
2324
Bank.SetupInterface();
2425
end;
2526

osrs/interfaces/slotinterface.simba

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ function TRSSlotInterface.ReadStack(slot: TBox): Integer;
184184
var
185185
i: Integer;
186186
begin
187-
//b.X1 += Self.DiscoverOffset.X1;
188-
//b.Y1 += Self.DiscoverOffset.Y1 - 9;
187+
slot.Y1 -= 1;
189188
slot.X2 := slot.X1 + 35;
190-
slot.Y2 := slot.Y1 + 8;
189+
slot.Y2 := slot.Y1 + 11;
191190

192191
for i := 0 to High(RSColors.STACK_COLORS) do
193192
if Target.HasColor(RSColors.STACK_COLORS[i], 0, 1, slot) then
194193
Exit(OCR.RecognizeNumber(slot, OCR.PLAIN_11, [RSColors.STACK_COLORS[i]], 0) * Round(10 ** (3 * i)));
194+
Result := -1;
195195
end;
196196

197197
function TRSSlotInterface.ReadStack(slot: Integer): Integer; overload;

osrs/ocr/ocr.simba

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,89 +42,82 @@ end;
4242

4343

4444

45-
function TRSOCR.RecognizeStatic(Bounds: TBox; Font: TPixelFont; Colors: TColorArray; Tolerance: Single): String;
45+
function TRSOCR.RecognizeStatic(bounds: TBox; font: TPixelFont; colors: TColorArray; tolerance: Single): String;
4646
var
4747
img: TImage;
4848
begin
49-
img := TImage.CreateFromTarget(Bounds);
50-
img.ReplaceColorBinary(False, Colors, Tolerance);
51-
Result := Self.Engine.Recognize(img, Font, [0,0]);
49+
img := TImage.CreateFromTarget(bounds);
50+
img.ReplaceColorBinary(False, colors, tolerance);
51+
Result := Self.Engine.Recognize(img, font, [0,0]);
5252
img.Free();
5353
end;
5454

55-
function TRSOCR.RecognizeStaticInvert(Bounds: TBox; Font: TPixelFont; Colors: TColorArray): String;
55+
function TRSOCR.RecognizeStaticInvert(bounds: TBox; font: TPixelFont; colors: TColorArray): String;
5656
var
5757
img: TImage;
5858
begin
59-
img := TImage.CreateFromTarget(Bounds);
60-
img.ReplaceColorBinary(True, Colors);
61-
Result := Self.Engine.Recognize(img, Font, [0,0]);
59+
img := TImage.CreateFromTarget(bounds);
60+
img.ReplaceColorBinary(True, colors);
61+
Result := Self.Engine.Recognize(img, font, [0,0]);
6262
img.Free();
6363
end;
6464

65-
function TRSOCR.Recognize(Bounds: TBox; Font: TPixelFont; Colors: TColorArray; Tolerance: Single): String;
65+
function TRSOCR.Recognize(bounds: TBox; font: TPixelFont; colors: TColorArray; tolerance: Single): String;
6666
var
6767
img: TImage;
6868
begin
69-
img := TImage.CreateFromTarget(Bounds);
70-
img.ReplaceColorBinary(False, Colors, Tolerance);
69+
img := TImage.CreateFromTarget(bounds);
70+
img.ReplaceColorBinary(False, colors, tolerance);
7171
Result := Self.Engine.Recognize(img, Font);
7272
img.Free();
7373
end;
7474

75-
function TRSOCR.RecognizeLines(Bounds: TBox; Font: TPixelFont; Colors: TColorArray; Tolerance: Single): TStringArray;
75+
function TRSOCR.RecognizeLines(bounds: TBox; font: TPixelFont; colors: TColorArray; tolerance: Single): TStringArray;
7676
var
7777
img: TImage;
7878
begin
79-
img := TImage.CreateFromTarget(Bounds);
80-
img.ReplaceColorBinary(False, Colors, Tolerance);
81-
Result := Self.Engine.RecognizeLines(img, Font);
79+
img := TImage.CreateFromTarget(bounds);
80+
img.ReplaceColorBinary(False, colors, tolerance);
81+
Result := Self.Engine.RecognizeLines(img, font);
8282
img.Free();
8383
end;
8484

85-
function TRSOCR.RecognizeShadow(Bounds: TBox; Font: TPixelFont; Tolerance: Single): String;
85+
function TRSOCR.RecognizeShadow(bounds: TBox; font: TPixelFont; tolerance: Single): String;
8686
var
87-
Image: TImage;
88-
Shadows, ShadowsOffset: TPointArray;
89-
Color: TColor;
87+
image: TImage;
88+
shadows: TPointArray;
89+
color: TColor;
9090
begin
91-
Image := TImage.CreateFromTarget(Bounds);
92-
Shadows := Image.FindColor(0, 2.5, [1, 1, Image.Width - 1, Image.Height - 1]);
93-
Shadows := Shadows.Offset([-1,-1]).ExcludePoints(Shadows);
94-
Color := Image.GetColors(Shadows).Mode;
95-
Image.ReplaceColorBinary(False, Color, Tolerance);
96-
Result := Self.Engine.Recognize(Image, Font);
97-
Image.Free();
91+
image := TImage.CreateFromTarget(bounds);
92+
shadows := image.FindColor(0, 2.5, [1, 1, image.Width - 1, image.Height - 1]);
93+
shadows := Shadows.Offset([-1,-1]).ExcludePoints(shadows);
94+
color := image.GetColors(shadows).Mode;
95+
image.ReplaceColorBinary(False, color, tolerance);
96+
Result := Self.Engine.Recognize(image, font);
97+
image.Free();
9898
end;
9999

100-
function TRSOCR.RecognizeNumber(Bounds: TBox; Font: TPixelFont; Colors: TColorArray; Tolerance: Single): Integer;
101-
var
102-
img: TImage;
103-
txt: String;
100+
function TRSOCR.RecognizeNumber(bounds: TBox; font: TPixelFont; colors: TColorArray; tolerance: Single): Integer;
104101
begin
105-
img := TImage.CreateFromTarget(Bounds);
106-
img.ReplaceColorBinary(False, Colors, Tolerance);
107-
txt := Self.Engine.Recognize(img, Font);
108-
Result := txt.ExtractInteger();
109-
img.Free();
102+
Result := Self.Recognize(bounds, font, colors, tolerance).ExtractInteger();
110103
end;
111104

112-
function TRSOCR.Locate(Bounds: TBox; Text: String; Colors: TColorArray; Tolerance: Single; Font: TPixelFont): Single;
105+
function TRSOCR.Locate(bounds: TBox; Text: String; colors: TColorArray; tolerance: Single; font: TPixelFont): Single;
113106
var
114107
img: TImage;
115108
begin
116-
img := TImage.CreateFromTarget(Bounds);
117-
img.ReplaceColorBinary(False, Colors, Tolerance);
109+
img := TImage.CreateFromTarget(bounds);
110+
img.ReplaceColorBinary(False, colors, tolerance);
118111
Result := Self.Engine.Locate(img, Font, Text);
119112
img.Free();
120113
end;
121114

122-
function TRSOCR.LocateInvert(Bounds: TBox; Text: String; Colors: TColorArray; Tolerance: Single; Font: TPixelFont): Single;
115+
function TRSOCR.LocateInvert(bounds: TBox; Text: String; colors: TColorArray; tolerance: Single; font: TPixelFont): Single;
123116
var
124117
img: TImage;
125118
begin
126-
img := TImage.CreateFromTarget(Bounds);
127-
img.ReplaceColorBinary(True, Colors, Tolerance);
119+
img := TImage.CreateFromTarget(bounds);
120+
img.ReplaceColorBinary(True, colors, tolerance);
128121
img.Show();
129122
Result := Self.Engine.Locate(img, Font, Text);
130123
img.Free();
@@ -133,14 +126,14 @@ end;
133126
(*
134127
function CountItemStack(Area: TBox): Int64;
135128
const
136-
Colors = [RSColors.ITEM_TEXT_YELLOW, RSColors.ITEM_TEXT_WHITE, RSColors.ITEM_TEXT_GREEN];
129+
colors = [RScolors.ITEM_TEXT_YELLOW, RScolors.ITEM_TEXT_WHITE, RScolors.ITEM_TEXT_GREEN];
137130
Multipliers = [1, 1000, 1000000];
138131
var
139132
I: Integer;
140133
begin
141-
//for I := 0 to High(Colors) do
134+
//for I := 0 to High(colors) do
142135
//begin
143-
// Result := OCR.RecognizeNumber(Area, TOCRColorFilter.Create([Colors[I]]), FONT_PLAIN_11) * Multipliers[I];
136+
// Result := OCR.RecognizeNumber(Area, TOCRColorFilter.Create([colors[I]]), FONT_PLAIN_11) * Multipliers[I];
144137
// if (Result > 0) then
145138
// Exit;
146139
//end;

tests/001.simba

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ begin
2525
Assert(Inventory.Slots.CountEmpty() = 17);
2626
Assert(Inventory.Items.Contains('Air rune'));
2727
Assert(Inventory.Items.Contains('Super attack(4)'));
28-
29-
//Assert(Inventory.Slots.ReadStack(2) = 1);
30-
28+
Assert(Inventory.Slots.ReadStack(2) = 1);
29+
Assert(Inventory.Slots.ReadStack(4) = 2);
3130

3231
img.Free();
3332
end;

0 commit comments

Comments
 (0)