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
|
(*find both min and max in list fast*)
minMax = Compile[{ {list, _Integer, 1} },
Module[{currentMin, currentMax},
currentMin = currentMax = First[list];
Do[Which[x < currentMin, currentMin = x, x > currentMax,
currentMax = x], {x, list}];
{currentMin, currentMax}], CompilationTarget -> "C",
RuntimeOptions -> "Speed"];
getpat[l_] := Module[{},
imd = ImageData[l];
If[Max[imd] == 0, Return["_"]];
dms = IntegerPart[Dimensions[imd]/2.];
If[Max[imd[[All, ;; dms[[2]]]]] == 0, Return["→"]];
If[Max[imd[[All, dms[[2]] ;;]]] == 0, Return["←"]];
If[Max[imd[[;; dms[[1]], All]]] == 0, Return["↓"]];
If[Max[imd[[dms[[1]] ;;, All]]] == 0, Return["↑"]];
Return["D"]
];
GetFrogManiaMatrix[img_] := Module[{TimeScoreOuterColor = {248, 217, 152}/255., PoolColor = {120, 211, 255}/255., EyeColor = 0.95, minx, t, imgt},
(* get only the pool zone*)
minx = Max[PixelValuePositions[img, TimeScoreOuterColor][[All, 1]]];
t = Transpose[Select[Sort[PixelValuePositions[img, PoolColor]], #[[1]] > minx &]];
imgt = ImageTrim[img, Transpose[Map[minMax, t]]];
Map[getpat, ImagePartition[Binarize[imgt, EyeColor], ImageDimensions[imgt]/{6, 5}], {2}] // Grid
]
GetFrogManiaMatrix[img]
_ ↓ _ ← ↓ ←
← _ _ D ↓ _
D _ _ _ _ _
_ → _ ↓ D _
↑ _ → → D ↑
|