-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathSolver.m
38 lines (34 loc) · 1.13 KB
/
MathSolver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
areaLeft = 500;
areaTop = 150;
areaWidth = 300;
areaHeight = 200;
desiredScore = 100;
symbolsChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ...
'Plus', 'Minus', 'Multiply', 'Divide', 'Equal'};
symbolImages = {};
for i=1:length(symbolsChar)
symbol = imread(sprintf('Symbols\\%s.png',symbolsChar{i}));
symbol = rgb2gray(symbol);
symbol = mat2gray(symbol);
symbol = symbol - mean(symbol(:));
symbol = symbol - var(symbol(:));
symbolImages{i} = symbol;
end
robo = java.awt.Robot;
while(desiredScore > 0)
pause(0.1);
img = captureScreen(areaLeft,areaTop,areaWidth,areaHeight);
% img = imread('Samples\Sample5.png');
% img = img(areaTop:areaTop+areaHeight,areaLeft:areaLeft+areaWidth,:);
img = mat2gray(rgb2gray(img));
result = evaluateImageEquation(img, symbolImages, symbolsChar);
if(result==2)
desiredScore = desiredScore - 1;
robo.keyPress(java.awt.event.KeyEvent.VK_LEFT);
elseif(result==1)
desiredScore = desiredScore - 1;
robo.keyPress(java.awt.event.KeyEvent.VK_RIGHT);
else
% fprintf('Cannot find equation on screen.\n');
end
end