tracking of positions

This commit is contained in:
Scott Pruett 2022-06-05 14:09:35 -04:00
parent 1502110e62
commit d4c87855cc
12 changed files with 403 additions and 304 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target /target
/ocr_data /ocr_data
/ocr_data_old

View File

@ -1,14 +1,5 @@
{ {
"ocr_regions": [ "ocr_regions": [
{
"name": "lap",
"x": 2300,
"y": 46,
"width": 140,
"height": 90,
"threshold": null,
"use_ocr_cache": null
},
{ {
"name": "health", "name": "health",
"x": 90, "x": 90,
@ -56,10 +47,17 @@
}, },
{ {
"name": "position", "name": "position",
"x": 3, "x": 50,
"y": 52, "y": 44,
"width": 107, "width": 250,
"height": 79 "height": 100
},
{
"name": "lap",
"x": 2290,
"y": 44,
"width": 230,
"height": 100
} }
], ],
"track_region": { "track_region": {

186
ocr.json
View File

@ -1,101 +1,109 @@
{ {
"learned_chars": { "learned_chars": {
"//8P+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H/+//8=": "0",
"//8H4Afg/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+A/g5+fzz/PP88/zn/PP88/zz+fP5+Mf8H/+//8=": "0",
"/////P/8f/4//p//3//H++P78/sBwAGA//v/+//7//8=": "4",
"//8P4A/gD+AP/w//D/gP4AfA/8P/w4fAA+AD8B/8//8=": "5",
"//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5",
"//9/4H/wP/Af+A/8B/4DggODAYABgAGAAYD/g/+D//8=": "4",
"/////f/8f/w//5//j//H++f78/MBgP/z//v/+//7//8=": "4",
"/////wfwB+DD4cPBA+AP8Afgw8PDw4PBA+AH8P////8=": "8",
"//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7",
"////z/+fH/4H+AP4w/Dh8eHx4fHh8cPwA/gP/B/+//8=": "0",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/h//8=": "1",
"//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0",
"///f/w/wB+DH48fhB+AH4APgw8PDw8PDB+AP8P////8=": "8",
"/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8",
"//8f/Efx8+fz7/vP88fjww/I/8//z//n/+MH+A/+//8=": "9",
"//8/4I/g5//z//P/O/wL4OPH88/zz/fPx8cP4H/8//8=": "6",
"//8P8AfgA8CDgcGDwYPBg8GDwYPBg4OBA8AH4A/w//8=": "0",
"//8f+Afi88/zz/PPx+EP8OPH88/73/Pf48cH4H/+//8=": "8",
"/////wPwA+DD4P/h/+H/4H/wP/gP/gf+A8ADwP////8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cP8H/+//8=": "0",
"//8D4APg//P/+X/8P/4/8P/H/8//z//P8+cD8D////8=": "3",
"/////wPAA8DDwcPBw+H/4P/wf/A/8D/4P/w/+P////8=": "7",
"//8P+APw++f/7//v/+f/4//x//w//h//z/8DwAPA//8=": "2",
"/////wPAA8Dj4OPg4+B/8H/wP/g/+D/8H/wf/P////8=": "7",
"//8/+A/w5+fjz/PP88/zz/PP88/zz+PP5+cP8D/8//8=": "0",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+D////8=": "9",
"//8HwAfA//P/8f/8f/5/8P/H/8//3//P88cD8H/+//8=": "3",
"//8DwAPA+8/75//n//P/8//5//n//H/+f/4//z////8=": "7",
"//8/4Ifg5//z//P/O/wL4OPH88/zz/PP5+cP4H/8//8=": "6",
"//+//Q/4B/CD4cPjw8PDw+PDw+PD4QfgD/Af+H/+//8=": "0",
"//9/7x/AD+AH74f/g/AD4APAg8OHwwfDD8Af4H/7//8=": "6",
"//8f+Afw++f/7//v/+f/4//4f/w//4//x/8DwAPA//8=": "2",
"///f/Q/wB+CH4cPDw8PDw8PDw8PDwwfgB/AP+L/9//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBB+Af8H/9//8=": "6",
"//8H4Afi//P/+P/8f/4/8P/j/8f/z//H8+MD8D/+//8=": "3",
"//8P4A/g7//n/+f/B/wH8P/H/8//3//P88cD8H/+//8=": "5",
"//8DwAPA88/z5//j/+P/8f/5//j//H/+P/4//h////8=": "7",
"//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//AA8AD4AP4//8=": "9",
"//8f+Afg5+fzz/PP+9/73/vf+9/zz+PP5+cP4B/4//8=": "0",
"/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2",
"//9/7x/AD+AH7of/g/AD4APAg8ODwwfDD+Af4H/7//8=": "6",
"/////wfgB+B/4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7",
"////+z/4P/wf/g/+D/+H8cPwA8ADwAPAA8D/8P////8=": "4", "////+z/4P/wf/g/+D/+H8cPwA8ADwAPAA8D/8P////8=": "4",
"//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", "//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5",
"//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".", "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0",
"//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3", "//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0",
"//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1", "//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".",
"//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", "//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7",
"///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", "/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8",
"/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4", "//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7",
"//8HwAfA/+P/8//9f/x/8P/H/8//3//P888D4B/4//8=": "3",
"///f/Q/4B/DD48PDw8EHwA/AH8P/4U/gB/AH+F////8=": "9",
"//8/8A/lx//3//P/8/8b4MPH48/z3/PP58eH4D/8//8=": "6",
"/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":",
"//8f/Efh4+fzz/PP88fnwwfY/9//z//v/+On8A/8//8=": "9",
"////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".", "////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".",
"//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3", "////8H/wf/g/+D/8H/wf/g/+D/8H/4f/g//D/8H///8=": "/",
"/////wfgB+Af4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"/////wfgB+A/4D/gP+A/4D/gP+A/4D/gP+A/4P////8=": "1",
"//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6", "//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6",
"//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9", "//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9",
"//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5", "//8P8AfgA8CBgcGDwYPBg8GDwYPBg4GBA8AH4A/w//8=": "0",
"//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", "////4P/wf/B/+D/4H/wf/B/+D/4H/wf/h/+D/8H///8=": "/",
"/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2", "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3", "/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":",
"//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", "//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/A/8//8=": "1",
"//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2", "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3",
"//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5", "/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2",
"//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6", "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3",
"/////w/wD/D/////////////////////D/AP8P////8=": ":",
"//8f/Afw5+fz5/HP+c/5z/nP+c/xz/Pn5+cP8B/8//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBD+Af8H/9//8=": "6",
"//8BgAGAAYA/gD+AP4A/gD+AP4A/gD+AP4A/gD+A//8=": "1",
"///f/Q/4B/DD4cPDw8EDwA/AH+P/4W/gB/AH+F////8=": "9",
"//8DwAPA+8/75//n//P/8f/5//n//H/+f/4//z////8=": "7",
"//8/gA+AB4AD34H/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+J////8=": "9",
"//8H8APAAcDDgP+B/4H/wH/gH/AP+Af8A4ADgAOA//8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cf8H/+//8=": "0",
"///v/QfwA+DD4cPBw8EDwAfAn8H/4UfwB/AD/G////8=": "9",
"/////P/8f/4//p//3//n++P78/sBwAGA//v/+//7//8=": "4",
"/////////////wfgB+AH4AfgB+AH4P////////////8=": "-",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/j//8=": "1",
"//8H4AfgB+D/8H/4P/w/8D/g/8P/w4fAA+AD8B/8//8=": "3",
"//8P8APAA8CBgYGDA8AH4APAgYHBg8GDgYEDwAfg//8=": "8",
"//8P+APw++f/7//v/+f/8//x//w//h//z/8DwAPA//8=": "2",
"//8f+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H////8=": "0", "//8f+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H////8=": "0",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/h//8=": "1",
"//8DwAPA88/z5//j/+P/8f/5//j//H/+P/4//h////8=": "7",
"/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2",
"//////////8BgAGAAYABgAGAAYABgAGA//////////8=": "-",
"//8H4Afi//P/+P/8f/4/8P/j/8f/z//H8+MD8D/+//8=": "3",
"//8/4I/g5//z//P/O/wL4OPH88/zz/fPx8cP4H/8//8=": "6",
"////z/+fH/4H+AP4w/Dh8eHx4fHh8cPwA/gP/B/+//8=": "0",
"//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0",
"/////wfwB+DD4cPBA+AP8Afgw8PDw4PBA+AH8P////8=": "8",
"//8H4AfgB+D/8H/4P/w/8D/g/8P/w4fAA+AD8B/8//8=": "3",
"/////P/8f/4//p//3//H++P78/sBwAGA//v/+//7//8=": "4",
"//8/+A/w5+fjz/PP88/zz/PP88/zz+PP5+cP8D/8//8=": "0",
"//8DwAPA+8/75//n//P/8f/5//n//H/+f/4//z////8=": "7",
"//8P4A/gD+AP/w//D/gP4AfA/8P/w4fAA+AD8B/8//8=": "5",
"//9/7x/AD+AH74f/g/AD4APAg8OHwwfDD8Af4H/7//8=": "6",
"//9/7x/AD+AH7of/g/AD4APAg8ODwwfDD+Af4H/7//8=": "6",
"//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/B/8//8=": "1",
"/////wPAA8DDwcPBw+H/4P/wf/A/8D/4P/w/+P////8=": "7",
"//8HwAfA/+P/8//9f/x/8P/H/8//3//P888D4B/4//8=": "3",
"//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5",
"//8HwAfAB8D/4H/wP/g/4D/A/8H/w4fAA8AD8B/8//8=": "3", "//8HwAfAB8D/4H/wP/g/4D/A/8H/w4fAA8AD8B/8//8=": "3",
"//8f+APwAcDDwP/B/8H/4H/wH/gP/APAA4ADgAOA//8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cP8H/+//8=": "0",
"///f/Q/4B/DD4cPDw8EDwA/AH+P/4W/gB/AH+F////8=": "9",
"//8P8APAA8CBgYGDA8AH4APAgYHBg8GDgYEDwAfg//8=": "8",
"///f/Q/wB+CH4cPDw8PDw8PDw8PDwwfgB/AP+L/9//8=": "0",
"/////wfgB+Af4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8f+Afg5+fzz/PP+9/73/vf+9/zz+PP5+cP4B/4//8=": "0",
"//8P+APw++f/7//v/+f/8//x//w//h//z/8DwAPA//8=": "2",
"///f/Q/4B/DD48PDw8EHwA/AH8P/4U/gB/AH+F////8=": "9",
"//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0",
"//8P4A/g7//n/+f/B/wH8P/H/8//3//P88cD8H/+//8=": "5",
"//8H8APAAcDDgP+B/4H/wH/gH/AP+Af8A4ADgAOA//8=": "2",
"/////wPwA+DD4P/h/+H/4H/wP/gP/gf+A8ADwP////8=": "2",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBD+Af8H/9//8=": "6",
"/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4",
"//8f+A/g5+fzz/PP88/zn/PP88/zz+fP5+Mf8H/+//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBB+Af8H/9//8=": "6",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3",
"///f/w/wB+DH48fhB+AH4APgw8PDw8PDB+AP8P////8=": "8",
"//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//BA8AD4AP4//8=": "9",
"//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+Afw++f/7//v/+f/4//4f/w//4//x/8DwAPA//8=": "2",
"//+//R/4D/CH4cPDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0", "//+//R/4D/CH4cPDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"//+//R/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".",
"////+3/4P/w//B/+D/8H8YfhA8ADwAPAA8D/4f////8=": "4", "////+3/4P/w//B/+D/8H8YfhA8ADwAPAA8D/4f////8=": "4",
"//////////8BgAGAAYABgAGAAYABgAGA//////////8=": "-" "//+//Q/4B/CD4cPjw8PDw+PDw+PD4QfgD/Af+H/+//8=": "0",
"//9/4H/wP/Af+A/8B/4DggODAYABgAGAAYD/g/+D//8=": "4",
"//8H4Afg/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cf8H/+//8=": "0",
"//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3",
"//8/gA+AB4AD34H/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"//8f+AfgA8CDwf+D/8H/wH/gH/AP/AfAA4ADgAOA//8=": "2",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+J////8=": "9",
"//8f/Efh4+fzz/PP88fnwwfY/9//z//v/+On8A/8//8=": "9",
"//8f/Efx8+fz7/vP88fjww/I/8//z//n/+MH+A/+//8=": "9",
"/////wfgB+B/4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8/8A/lx//3//P/8/8b4MPH48/z3/PP58eH4D/8//8=": "6",
"/////f/8f/w//5//j//H++f78/MBgP/z//v/+//7//8=": "4",
"/////wPAA8Dj4OPg4+B/8H/wP/g/+D/8H/wf/P////8=": "7",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/j//8=": "1",
"//+//R/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"/////w/wD/D/////////////////////D/AP8P////8=": ":",
"///v/QfwA+DD4cPBw8EDwAfAn8H/4UfwB/AD/G////8=": "9",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+D////8=": "9",
"//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"/////wfgB+A/4D/gP+A/4D/gP+A/4D/gP+A/4P////8=": "1",
"/////////////wfgB+AH4AfgB+AH4P////////////8=": "-",
"//8P8AfgA8CDgcGDwYPBg8GDwYPBg4OBA8AH4A/w//8=": "0",
"//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3",
"//8D4APg//P/+X/8P/4/8P/H/8//z//P8+cD8D////8=": "3",
"//8DwAPA+8/75//n//P/8//5//n//H/+f/4//z////8=": "7",
"//8f+Afi88/zz/PPx+EP8OPH88/73/Pf48cH4H/+//8=": "8",
"//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2",
"/////P/8f/4//p//3//n++P78/sBwAGA//v/+//7//8=": "4",
"//8f/Afw5+fz5/HP+c/5z/nP+c/xz/Pn5+cP8B/8//8=": "0",
"//8P+APw++f/7//v/+f/4//x//w//h//z/8DwAPA//8=": "2",
"//8BgAGAAYA/gD+AP4A/gD+AP4A/gD+AP4A/gD+A//8=": "1",
"//8/4Ifg5//z//P/O/wL4OPH88/zz/PP5+cP4H/8//8=": "6",
"//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".",
"//8P+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H/+//8=": "0",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//AA8AD4AP4//8=": "9",
"//8HwAfA//P/8f/8f/5/8P/H/8//3//P88cD8H/+//8=": "3"
} }
} }

View File

@ -55,11 +55,14 @@ fn merge_with_max<T: Ord + Clone>(a: &Option<T>, b: &Option<T>) -> Option<T> {
fn merge_frames(prev: &LapState, next: &LapState) -> LapState { fn merge_frames(prev: &LapState, next: &LapState) -> LapState {
LapState { LapState {
lap: merge_with_max(&prev.lap, &next.lap), lap: merge_with_max(&prev.lap, &next.lap),
total_laps: merge_with_max(&prev.total_laps, &next.total_laps),
health: merge_with_max(&prev.health, &next.health), health: merge_with_max(&prev.health, &next.health),
gas: merge_with_max(&prev.gas, &next.gas), gas: merge_with_max(&prev.gas, &next.gas),
tyres: merge_with_max(&prev.tyres, &next.tyres), tyres: merge_with_max(&prev.tyres, &next.tyres),
lap_time: merge_with_max(&prev.lap_time, &next.lap_time), lap_time: merge_with_max(&prev.lap_time, &next.lap_time),
best_time: merge_with_max(&prev.best_time, &next.best_time), best_time: merge_with_max(&prev.best_time, &next.best_time),
position: merge_with_max(&prev.position, &next.position),
total_positions: merge_with_max(&prev.total_positions, &next.total_positions),
..Default::default() ..Default::default()
} }
} }
@ -252,6 +255,7 @@ mod test {
load_config_or_make_default("src/configs/config.default.json", "").unwrap(), load_config_or_make_default("src/configs/config.default.json", "").unwrap(),
), ),
ocr_db: Arc::new(OcrDatabase::load().unwrap()), ocr_db: Arc::new(OcrDatabase::load().unwrap()),
should_sample_ocr_data: true,
..Default::default() ..Default::default()
}; };
Arc::new(Mutex::new(state)) Arc::new(Mutex::new(state))
@ -265,13 +269,16 @@ mod test {
let lap_state = state.lock().unwrap().last_frame.as_ref().unwrap().clone(); let lap_state = state.lock().unwrap().last_frame.as_ref().unwrap().clone();
assert_eq!(4, lap_state.lap.unwrap()); assert_eq!(4, lap_state.lap.unwrap());
assert_eq!(5, lap_state.total_laps.unwrap());
assert_eq!(10, lap_state.position.unwrap());
assert_eq!(12, lap_state.total_positions.unwrap());
assert_eq!(95, lap_state.health.unwrap()); assert_eq!(95, lap_state.health.unwrap());
assert_eq!(79, lap_state.gas.unwrap()); assert_eq!(79, lap_state.gas.unwrap());
assert_eq!(76, lap_state.tyres.unwrap()); assert_eq!(76, lap_state.tyres.unwrap());
assert!( assert!(
Duration::from_secs(24) <= lap_state.lap_time.unwrap() Duration::from_secs(49) <= lap_state.lap_time.unwrap()
&& lap_state.lap_time.unwrap() <= Duration::from_secs(25) && lap_state.lap_time.unwrap() <= Duration::from_secs(50)
); );
} }
} }

View File

@ -1,62 +1,77 @@
{ {
"ocr_regions": [ "ocr_regions": [
{ {
"name": "lap", "name": "health",
"x": 2300, "x": 90,
"y": 46, "y": 1364,
"width": 140, "width": 52,
"height": 90 "height": 24,
}, "threshold": null,
{ "use_ocr_cache": null
"name": "health", },
"x": 90, {
"y": 1364, "name": "gas",
"width": 52, "x": 208,
"height": 24 "y": 1364,
}, "width": 52,
{ "height": 24,
"name": "gas", "threshold": null,
"x": 208, "use_ocr_cache": null
"y": 1364, },
"width": 52, {
"height": 24 "name": "tyres",
}, "x": 325,
{ "y": 1364,
"name": "tyres", "width": 52,
"x": 325, "height": 24,
"y": 1364, "threshold": null,
"width": 52, "use_ocr_cache": null
"height": 24 },
}, {
{ "name": "best",
"name": "best", "x": 2325,
"x": 2325, "y": 169,
"y": 169, "width": 183,
"width": 183, "height": 43,
"height": 43 "threshold": null,
}, "use_ocr_cache": null
{ },
"name": "lap_time", {
"x": 2325, "name": "lap_time",
"y": 222, "x": 2325,
"width": 183, "y": 222,
"height": 43 "width": 183,
} "height": 43,
], "threshold": null,
"track_region": { "use_ocr_cache": null
"name": "track", },
"x": 2020, {
"y": 1030, "name": "position",
"width": 540, "x": 50,
"height": 410, "y": 44,
"threshold": 0.85 "width": 250,
}, "height": 100
"penalty_orange_region": { },
"name": "penalty", {
"x": 989, "name": "lap",
"y": 117, "x": 2290,
"width": 30, "y": 44,
"height": 30 "width": 230,
}, "height": 100
"track_recognition_threshold": 10 }
],
"track_region": {
"name": "track",
"x": 2020,
"y": 1030,
"width": 540,
"height": 410,
"threshold": 0.85,
"use_ocr_cache": null
},
"ocr_interval_ms": 500,
"track_recognition_threshold": 10,
"dump_frame_fraction": null,
"light_mode": false,
"font_scale": 1.3
} }

View File

@ -1,101 +1,109 @@
{ {
"learned_chars": { "learned_chars": {
"//8P+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H/+//8=": "0",
"//8H4Afg/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+A/g5+fzz/PP88/zn/PP88/zz+fP5+Mf8H/+//8=": "0",
"/////P/8f/4//p//3//H++P78/sBwAGA//v/+//7//8=": "4",
"//8P4A/gD+AP/w//D/gP4AfA/8P/w4fAA+AD8B/8//8=": "5",
"//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5",
"//9/4H/wP/Af+A/8B/4DggODAYABgAGAAYD/g/+D//8=": "4",
"/////f/8f/w//5//j//H++f78/MBgP/z//v/+//7//8=": "4",
"/////wfwB+DD4cPBA+AP8Afgw8PDw4PBA+AH8P////8=": "8",
"//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7",
"////z/+fH/4H+AP4w/Dh8eHx4fHh8cPwA/gP/B/+//8=": "0",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/h//8=": "1",
"//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0",
"///f/w/wB+DH48fhB+AH4APgw8PDw8PDB+AP8P////8=": "8",
"/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8",
"//8f/Efx8+fz7/vP88fjww/I/8//z//n/+MH+A/+//8=": "9",
"//8/4I/g5//z//P/O/wL4OPH88/zz/fPx8cP4H/8//8=": "6",
"//8P8AfgA8CDgcGDwYPBg8GDwYPBg4OBA8AH4A/w//8=": "0",
"//8f+Afi88/zz/PPx+EP8OPH88/73/Pf48cH4H/+//8=": "8",
"/////wPwA+DD4P/h/+H/4H/wP/gP/gf+A8ADwP////8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cP8H/+//8=": "0",
"//8D4APg//P/+X/8P/4/8P/H/8//z//P8+cD8D////8=": "3",
"/////wPAA8DDwcPBw+H/4P/wf/A/8D/4P/w/+P////8=": "7",
"//8P+APw++f/7//v/+f/4//x//w//h//z/8DwAPA//8=": "2",
"/////wPAA8Dj4OPg4+B/8H/wP/g/+D/8H/wf/P////8=": "7",
"//8/+A/w5+fjz/PP88/zz/PP88/zz+PP5+cP8D/8//8=": "0",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+D////8=": "9",
"//8HwAfA//P/8f/8f/5/8P/H/8//3//P88cD8H/+//8=": "3",
"//8DwAPA+8/75//n//P/8//5//n//H/+f/4//z////8=": "7",
"//8/4Ifg5//z//P/O/wL4OPH88/zz/PP5+cP4H/8//8=": "6",
"//+//Q/4B/CD4cPjw8PDw+PDw+PD4QfgD/Af+H/+//8=": "0",
"//9/7x/AD+AH74f/g/AD4APAg8OHwwfDD8Af4H/7//8=": "6",
"//8f+Afw++f/7//v/+f/4//4f/w//4//x/8DwAPA//8=": "2",
"///f/Q/wB+CH4cPDw8PDw8PDw8PDwwfgB/AP+L/9//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBB+Af8H/9//8=": "6",
"//8H4Afi//P/+P/8f/4/8P/j/8f/z//H8+MD8D/+//8=": "3",
"//8P4A/g7//n/+f/B/wH8P/H/8//3//P88cD8H/+//8=": "5",
"//8DwAPA88/z5//j/+P/8f/5//j//H/+P/4//h////8=": "7",
"//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//AA8AD4AP4//8=": "9",
"//8f+Afg5+fzz/PP+9/73/vf+9/zz+PP5+cP4B/4//8=": "0",
"/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2",
"//9/7x/AD+AH7of/g/AD4APAg8ODwwfDD+Af4H/7//8=": "6",
"/////wfgB+B/4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7",
"////+z/4P/wf/g/+D/+H8cPwA8ADwAPAA8D/8P////8=": "4", "////+z/4P/wf/g/+D/+H8cPwA8ADwAPAA8D/8P////8=": "4",
"//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", "//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5",
"//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".", "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0",
"//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3", "//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0",
"//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1", "//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".",
"//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", "//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7",
"///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", "/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8",
"/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4", "//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7",
"//8HwAfA/+P/8//9f/x/8P/H/8//3//P888D4B/4//8=": "3",
"///f/Q/4B/DD48PDw8EHwA/AH8P/4U/gB/AH+F////8=": "9",
"//8/8A/lx//3//P/8/8b4MPH48/z3/PP58eH4D/8//8=": "6",
"/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":",
"//8f/Efh4+fzz/PP88fnwwfY/9//z//v/+On8A/8//8=": "9",
"////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".", "////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".",
"//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3", "////8H/wf/g/+D/8H/wf/g/+D/8H/4f/g//D/8H///8=": "/",
"/////wfgB+Af4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"/////wfgB+A/4D/gP+A/4D/gP+A/4D/gP+A/4P////8=": "1",
"//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6", "//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6",
"//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9", "//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9",
"//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5", "//8P8AfgA8CBgcGDwYPBg8GDwYPBg4GBA8AH4A/w//8=": "0",
"//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", "////4P/wf/B/+D/4H/wf/B/+D/4H/wf/h/+D/8H///8=": "/",
"/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2", "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3", "/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":",
"//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", "//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/A/8//8=": "1",
"//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2", "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3",
"//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5", "/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2",
"//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6", "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3",
"/////w/wD/D/////////////////////D/AP8P////8=": ":",
"//8f/Afw5+fz5/HP+c/5z/nP+c/xz/Pn5+cP8B/8//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBD+Af8H/9//8=": "6",
"//8BgAGAAYA/gD+AP4A/gD+AP4A/gD+AP4A/gD+A//8=": "1",
"///f/Q/4B/DD4cPDw8EDwA/AH+P/4W/gB/AH+F////8=": "9",
"//8DwAPA+8/75//n//P/8f/5//n//H/+f/4//z////8=": "7",
"//8/gA+AB4AD34H/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+J////8=": "9",
"//8H8APAAcDDgP+B/4H/wH/gH/AP+Af8A4ADgAOA//8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cf8H/+//8=": "0",
"///v/QfwA+DD4cPBw8EDwAfAn8H/4UfwB/AD/G////8=": "9",
"/////P/8f/4//p//3//n++P78/sBwAGA//v/+//7//8=": "4",
"/////////////wfgB+AH4AfgB+AH4P////////////8=": "-",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/j//8=": "1",
"//8H4AfgB+D/8H/4P/w/8D/g/8P/w4fAA+AD8B/8//8=": "3",
"//8P8APAA8CBgYGDA8AH4APAgYHBg8GDgYEDwAfg//8=": "8",
"//8P+APw++f/7//v/+f/8//x//w//h//z/8DwAPA//8=": "2",
"//8f+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H////8=": "0", "//8f+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H////8=": "0",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/h//8=": "1",
"//8DwAPA88/z5//j/+P/8f/5//j//H/+P/4//h////8=": "7",
"/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2",
"//////////8BgAGAAYABgAGAAYABgAGA//////////8=": "-",
"//8H4Afi//P/+P/8f/4/8P/j/8f/z//H8+MD8D/+//8=": "3",
"//8/4I/g5//z//P/O/wL4OPH88/zz/fPx8cP4H/8//8=": "6",
"////z/+fH/4H+AP4w/Dh8eHx4fHh8cPwA/gP/B/+//8=": "0",
"//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0",
"/////wfwB+DD4cPBA+AP8Afgw8PDw4PBA+AH8P////8=": "8",
"//8H4AfgB+D/8H/4P/w/8D/g/8P/w4fAA+AD8B/8//8=": "3",
"/////P/8f/4//p//3//H++P78/sBwAGA//v/+//7//8=": "4",
"//8/+A/w5+fjz/PP88/zz/PP88/zz+PP5+cP8D/8//8=": "0",
"//8DwAPA+8/75//n//P/8f/5//n//H/+f/4//z////8=": "7",
"//8P4A/gD+AP/w//D/gP4AfA/8P/w4fAA+AD8B/8//8=": "5",
"//9/7x/AD+AH74f/g/AD4APAg8OHwwfDD8Af4H/7//8=": "6",
"//9/7x/AD+AH7of/g/AD4APAg8ODwwfDD+Af4H/7//8=": "6",
"//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/B/8//8=": "1",
"/////wPAA8DDwcPBw+H/4P/wf/A/8D/4P/w/+P////8=": "7",
"//8HwAfA/+P/8//9f/x/8P/H/8//3//P888D4B/4//8=": "3",
"//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5",
"//8HwAfAB8D/4H/wP/g/4D/A/8H/w4fAA8AD8B/8//8=": "3", "//8HwAfAB8D/4H/wP/g/4D/A/8H/w4fAA8AD8B/8//8=": "3",
"//8f+APwAcDDwP/B/8H/4H/wH/gP/APAA4ADgAOA//8=": "2",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cP8H/+//8=": "0",
"///f/Q/4B/DD4cPDw8EDwA/AH+P/4W/gB/AH+F////8=": "9",
"//8P8APAA8CBgYGDA8AH4APAgYHBg8GDgYEDwAfg//8=": "8",
"///f/Q/wB+CH4cPDw8PDw8PDw8PDwwfgB/AP+L/9//8=": "0",
"/////wfgB+Af4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8f+Afg5+fzz/PP+9/73/vf+9/zz+PP5+cP4B/4//8=": "0",
"//8P+APw++f/7//v/+f/8//x//w//h//z/8DwAPA//8=": "2",
"///f/Q/4B/DD48PDw8EHwA/AH8P/4U/gB/AH+F////8=": "9",
"//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0",
"//8P4A/g7//n/+f/B/wH8P/H/8//3//P88cD8H/+//8=": "5",
"//8H8APAAcDDgP+B/4H/wH/gH/AP+Af8A4ADgAOA//8=": "2",
"/////wPwA+DD4P/h/+H/4H/wP/gP/gf+A8ADwP////8=": "2",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBD+Af8H/9//8=": "6",
"/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4",
"//8f+A/g5+fzz/PP88/zn/PP88/zz+fP5+Mf8H/+//8=": "0",
"//9/7x/gD+AH/4P/g/gD4APAg8ODw4fBB+Af8H/9//8=": "6",
"//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3",
"///f/w/wB+DH48fhB+AH4APgw8PDw8PDB+AP8P////8=": "8",
"//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//BA8AD4AP4//8=": "9",
"//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+Afw++f/7//v/+f/4//4f/w//4//x/8DwAPA//8=": "2",
"//+//R/4D/CH4cPDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0", "//+//R/4D/CH4cPDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"//+//R/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".",
"////+3/4P/w//B/+D/8H8YfhA8ADwAPAA8D/4f////8=": "4", "////+3/4P/w//B/+D/8H8YfhA8ADwAPAA8D/4f////8=": "4",
"//////////8BgAGAAYABgAGAAYABgAGA//////////8=": "-" "//+//Q/4B/CD4cPjw8PDw+PDw+PD4QfgD/Af+H/+//8=": "0",
"//9/4H/wP/Af+A/8B/4DggODAYABgAGAAYD/g/+D//8=": "4",
"//8H4Afg/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1",
"//8f+A/g5+fzz/PP88/zz/PP88/zz+fH5+cf8H/+//8=": "0",
"//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3",
"//8/gA+AB4AD34H/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"//8f+AfgA8CDwf+D/8H/wH/gH/AP/AfAA4ADgAOA//8=": "2",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+J////8=": "9",
"//8f/Efh4+fzz/PP88fnwwfY/9//z//v/+On8A/8//8=": "9",
"//8f/Efx8+fz7/vP88fjww/I/8//z//n/+MH+A/+//8=": "9",
"/////wfgB+B/4H/gf+B/4H/gf+B/4H/gf+B/4P////8=": "1",
"//8/8A/lx//3//P/8/8b4MPH48/z3/PP58eH4D/8//8=": "6",
"/////f/8f/w//5//j//H++f78/MBgP/z//v/+//7//8=": "4",
"/////wPAA8Dj4OPg4+B/8H/wP/g/+D/8H/wf/P////8=": "7",
"//8H4Afg/+H/4f/h/+H/4f/h/+H/4f/h/+H/4f/j//8=": "1",
"//+//R/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0",
"/////w/wD/D/////////////////////D/AP8P////8=": ":",
"///v/QfwA+DD4cPBw8EDwAfAn8H/4UfwB/AD/G////8=": "9",
"//8P+CPw8+f77/vP88fjwQ/M/8//z//n//EH+D////8=": "9",
"//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6",
"/////wfgB+A/4D/gP+A/4D/gP+A/4D/gP+A/4P////8=": "1",
"/////////////wfgB+AH4AfgB+AH4P////////////8=": "-",
"//8P8AfgA8CDgcGDwYPBg8GDwYPBg4OBA8AH4A/w//8=": "0",
"//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3",
"//8D4APg//P/+X/8P/4/8P/H/8//z//P8+cD8D////8=": "3",
"//8DwAPA+8/75//n//P/8//5//n//H/+f/4//z////8=": "7",
"//8f+Afi88/zz/PPx+EP8OPH88/73/Pf48cH4H/+//8=": "8",
"//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2",
"/////P/8f/4//p//3//n++P78/sBwAGA//v/+//7//8=": "4",
"//8f/Afw5+fz5/HP+c/5z/nP+c/xz/Pn5+cP8B/8//8=": "0",
"//8P+APw++f/7//v/+f/4//x//w//h//z/8DwAPA//8=": "2",
"//8BgAGAAYA/gD+AP4A/gD+AP4A/gD+AP4A/gD+A//8=": "1",
"//8/4Ifg5//z//P/O/wL4OPH88/zz/PP5+cP4H/8//8=": "6",
"//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".",
"//8P+Afw4+fzx/HP+c/5z/nP8c/zx/Pnx/MP+H/+//8=": "0",
"//8P8APgAcDBgcGDwYEBgAOAD4L/g//AA8AD4AP4//8=": "9",
"//8HwAfA//P/8f/8f/5/8P/H/8//3//P88cD8H/+//8=": "3"
} }
} }

View File

@ -180,6 +180,7 @@ fn show_race_state(
) { ) {
egui::Grid::new(format!("race:{}", race_name)).show(ui, |ui| { egui::Grid::new(format!("race:{}", race_name)).show(ui, |ui| {
ui.label("Lap"); ui.label("Lap");
ui.label("Position");
ui.label("Time"); ui.label("Time");
ui.label("Δ Previous"); ui.label("Δ Previous");
ui.label("Δ Best"); ui.label("Δ Best");
@ -192,6 +193,7 @@ fn show_race_state(
for (i, lap) in race.laps.iter_mut().enumerate() { for (i, lap) in race.laps.iter_mut().enumerate() {
if let Some(lap_time) = lap.lap_time { if let Some(lap_time) = lap.lap_time {
ui.label(format!("#{}", lap.lap.unwrap_or(i + 1))); ui.label(format!("#{}", lap.lap.unwrap_or(i + 1)));
ui.label(format!("P{}", lap.position.unwrap_or_default()));
if Some(lap_time) == fastest_lap { if Some(lap_time) == fastest_lap {
ui.colored_label(Color32::GREEN, format_time(lap_time)); ui.colored_label(Color32::GREEN, format_time(lap_time));
@ -337,7 +339,8 @@ impl eframe::App for AppUi {
egui::SidePanel::left("frame").min_width(180.).show(ctx, |ui| { egui::SidePanel::left("frame").min_width(180.).show(ctx, |ui| {
if let Some(frame) = &state.last_frame { if let Some(frame) = &state.last_frame {
ui.heading("Race data"); ui.heading("Race data");
ui.label(format!("Lap: {}", frame.lap.unwrap_or(0))); ui.label(format!("Lap: {}/{}", frame.lap.unwrap_or(0), frame.total_laps.unwrap_or(0)));
ui.label(format!("Position: {}/{}", frame.position.unwrap_or(0), frame.total_positions.unwrap_or(0)));
ui.separator(); ui.separator();
ui.label(format!("Health: {}/100", frame.health.unwrap_or(0))); ui.label(format!("Health: {}/100", frame.health.unwrap_or(0)));
ui.label(format!("Gas: {}/100", frame.gas.unwrap_or(0))); ui.label(format!("Gas: {}/100", frame.gas.unwrap_or(0)));

View File

@ -11,11 +11,15 @@ struct BoundingBox {
height: u32, height: u32,
} }
fn is_dark_pixel(image: &RgbImage, x: u32, y: u32) -> bool {
let [r, g, b] = image.get_pixel(x, y).0;
r < 100 && g < 100 && b < 100
}
fn column_has_any_dark(image: &RgbImage, x: u32) -> bool { fn column_has_any_dark(image: &RgbImage, x: u32) -> bool {
for y in 0..image.height() { for y in 0..image.height() {
let [r, g, b] = image.get_pixel(x, y).0; if is_dark_pixel(image, x, y) {
if r < 100 && g < 100 && b < 100 { return true
return true;
} }
} }
false false
@ -23,8 +27,7 @@ fn column_has_any_dark(image: &RgbImage, x: u32) -> bool {
fn row_has_any_dark(image: &RgbImage, y: u32, start_x: u32, width: u32) -> bool { fn row_has_any_dark(image: &RgbImage, y: u32, start_x: u32, width: u32) -> bool {
for x in start_x..(start_x + width) { for x in start_x..(start_x + width) {
let [r, g, b] = image.get_pixel(x, y).0; if is_dark_pixel(image, x, y) {
if r < 100 && g < 100 && b < 100 {
return true; return true;
} }
} }
@ -37,9 +40,25 @@ fn take_while<F: Fn(u32) -> bool>(x: &mut u32, max: u32, f: F) {
} }
} }
fn find_vertical_cutoff_from_right(image: &RgbImage) -> Option<(u32, u32)> {
let mut cutoffs = Vec::new();
for y in 0..image.height() {
for x in 0..image.width() {
let x = image.width() - 1 - x;
if is_dark_pixel(image, x, y) {
cutoffs.push((x, y));
break;
}
}
}
cutoffs.sort();
cutoffs.into_iter().skip(5).nth(0)
}
fn get_character_bounding_boxes(image: &RgbImage) -> Vec<BoundingBox> { fn get_character_bounding_boxes(image: &RgbImage) -> Vec<BoundingBox> {
let mut x = 0; let mut x = 0;
let mut boxes = Vec::new(); let mut boxes = Vec::new();
let (cutoff_x, cutoff_y) = find_vertical_cutoff_from_right(image).unwrap_or_default();
while x < image.width() { while x < image.width() {
take_while(&mut x, image.width(), |x| !column_has_any_dark(image, x)); take_while(&mut x, image.width(), |x| !column_has_any_dark(image, x));
@ -48,15 +67,15 @@ fn get_character_bounding_boxes(image: &RgbImage) -> Vec<BoundingBox> {
let width = x - start_x; let width = x - start_x;
if width >= 1 { if width >= 1 {
let mut y = 0; let mut y = if start_x > cutoff_x { cutoff_y } else { 0 };
take_while(&mut y, image.height(), |y| { take_while(&mut y, image.height(), |y| {
!row_has_any_dark(image, y, start_x, width) !row_has_any_dark(image, y, start_x, width)
}); });
let start_y = y; let start_y = y.min(image.height() - 1);
let mut inverse_y = 0; let mut inverse_y = 0;
take_while(&mut inverse_y, image.height(), |y| { take_while(&mut inverse_y, image.height() - start_y, |y| {
!row_has_any_dark(image, image.height() - 1 - y, start_x, width) !row_has_any_dark(image, image.height() - 1 - y, start_x, width)
}); });
let end_y = image.height() - inverse_y; let end_y = image.height() - inverse_y;
@ -114,22 +133,27 @@ pub fn compute_box_hashes(image: &RgbImage) -> Vec<ImageHash> {
hashes hashes
} }
#[test] #[cfg(test)]
fn test_bounding_boxes() { mod test {
let image_bytes = include_bytes!("test_data/test-montserrat.png"); use crate::ocr::{compute_box_hashes, get_character_bounding_boxes};
let image = image::load_from_memory(image_bytes).unwrap().to_rgb8();
let boxes = get_character_bounding_boxes(&image);
assert_eq!(boxes.len(), 10);
assert_ne!(boxes[0].x, 0);
assert_ne!(boxes[0].y, 0);
assert_ne!(boxes[0].height, 0);
assert_ne!(boxes[0].width, 0);
}
#[test] #[test]
fn test_box_hashes() { fn test_bounding_boxes() {
let image_bytes = include_bytes!("test_data/test-montserrat.png"); let image_bytes = include_bytes!("test_data/test-montserrat.png");
let image = image::load_from_memory(image_bytes).unwrap().to_rgb8(); let image = image::load_from_memory(image_bytes).unwrap().to_rgb8();
let hashes = compute_box_hashes(&image); let boxes = get_character_bounding_boxes(&image);
assert_eq!(hashes.len(), 10); assert_eq!(boxes.len(), 10);
assert_ne!(boxes[0].x, 0);
assert_ne!(boxes[0].y, 0);
assert_ne!(boxes[0].height, 0);
assert_ne!(boxes[0].width, 0);
}
#[test]
fn test_box_hashes() {
let image_bytes = include_bytes!("test_data/test-montserrat.png");
let image = image::load_from_memory(image_bytes).unwrap().to_rgb8();
let hashes = compute_box_hashes(&image);
assert_eq!(hashes.len(), 10);
}
} }

View File

@ -109,29 +109,39 @@ impl OcrDatabase {
} }
} }
#[test] #[cfg(test)]
fn test_ocr() { mod test {
let raw: RawOcrDatabase = use crate::ocr_db::{OcrDatabase, RawOcrDatabase};
serde_json::from_str(include_str!("configs/ocr.default.json")).unwrap();
let db: OcrDatabase = (&raw).into();
let image = image::load_from_memory(include_bytes!("test_data/test-time-1.png")) #[test]
.unwrap() fn test_ocr() {
.to_rgb8(); let raw: RawOcrDatabase =
assert_eq!(db.ocr_image(&image), "00:30.625"); serde_json::from_str(include_str!("configs/ocr.default.json")).unwrap();
let db: OcrDatabase = (&raw).into();
let image = image::load_from_memory(include_bytes!("test_data/test-time-2.png")) let image = image::load_from_memory(include_bytes!("test_data/test-time-1.png"))
.unwrap() .unwrap()
.to_rgb8(); .to_rgb8();
assert_eq!(db.ocr_image(&image), "00:20.296"); assert_eq!(db.ocr_image(&image), "00:30.625");
let image = image::load_from_memory(include_bytes!("test_data/test-num-1.png")) let image = image::load_from_memory(include_bytes!("test_data/test-time-2.png"))
.unwrap() .unwrap()
.to_rgb8(); .to_rgb8();
assert_eq!(db.ocr_image(&image), "1"); assert_eq!(db.ocr_image(&image), "00:20.296");
let image = image::load_from_memory(include_bytes!("test_data/test-blank.png")) let image = image::load_from_memory(include_bytes!("test_data/test-num-1.png"))
.unwrap() .unwrap()
.to_rgb8(); .to_rgb8();
assert_eq!(db.ocr_image(&image), ""); assert_eq!(db.ocr_image(&image), "1");
let image = image::load_from_memory(include_bytes!("test_data/test-blank.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "");
let image = image::load_from_memory(include_bytes!("test_data/test-pos-1.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "10/12");
}
} }

View File

@ -13,6 +13,10 @@ use crate::{config::Config, learned_tracks::LearnedTracks, ocr_db::OcrDatabase};
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct LapState { pub struct LapState {
pub lap: Option<usize>, pub lap: Option<usize>,
pub total_laps: Option<usize>,
pub position: Option<usize>,
pub total_positions: Option<usize>,
pub health: Option<usize>, pub health: Option<usize>,
pub gas: Option<usize>, pub gas: Option<usize>,
@ -52,10 +56,26 @@ fn parse_to_0_100(v: Option<&String>) -> Option<usize> {
check_0_100(v?.parse::<usize>().ok()?) check_0_100(v?.parse::<usize>().ok()?)
} }
fn parse_with_slash(v: Option<&String>) -> (Option<usize>, Option<usize>) {
let v = match v {
Some(v) => v,
None => return (None, None),
};
match v.split_once("/") {
Some((a, b)) => (a.parse().ok(), b.parse().ok()),
None => (v.parse().ok(), None),
}
}
impl LapState { impl LapState {
pub fn parse(raw: &HashMap<String, String>) -> Self { pub fn parse(raw: &HashMap<String, String>) -> Self {
let (lap, total_laps) = parse_with_slash(raw.get("lap"));
let (position, total_positions) = parse_with_slash(raw.get("position"));
Self { Self {
lap: parse_to_0_100(raw.get("lap")), lap,
total_laps,
position,
total_positions,
health: parse_to_0_100(raw.get("health")), health: parse_to_0_100(raw.get("health")),
gas: parse_to_0_100(raw.get("gas")), gas: parse_to_0_100(raw.get("gas")),
tyres: parse_to_0_100(raw.get("tyres")), tyres: parse_to_0_100(raw.get("tyres")),

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -97,10 +97,15 @@ impl eframe::App for TrainingUi {
ctx.set_visuals(Visuals::dark()); ctx.set_visuals(Visuals::dark());
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical().show(ui, |ui| { egui::ScrollArea::vertical().show(ui, |ui| {
let current_image = &mut self.training_images[self.current_image_index]; let training_images_len = self.training_images.len();
ui.heading(format!("{}/{}", self.current_image_index, training_images_len));
let current_image = &mut self.training_images[self.current_image_index % training_images_len];
if ui.button("Skip").clicked() { if ui.button("Skip").clicked() {
self.current_image_index += 1; self.current_image_index += 1;
} }
if ui.button("Back").clicked() {
self.current_image_index = self.current_image_index.saturating_sub(1);
}
if ui.button("Delete Data").clicked() { if ui.button("Delete Data").clicked() {
current_image.delete_data(); current_image.delete_data();
self.current_image_index += 1; self.current_image_index += 1;