diff --git a/.gitignore b/.gitignore index 167add6..000f3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/ocr_data \ No newline at end of file +/ocr_data +/ocr_data_old diff --git a/config.json b/config.json index 73e9110..3b82065 100644 --- a/config.json +++ b/config.json @@ -1,14 +1,5 @@ { "ocr_regions": [ - { - "name": "lap", - "x": 2300, - "y": 46, - "width": 140, - "height": 90, - "threshold": null, - "use_ocr_cache": null - }, { "name": "health", "x": 90, @@ -56,10 +47,17 @@ }, { "name": "position", - "x": 3, - "y": 52, - "width": 107, - "height": 79 + "x": 50, + "y": 44, + "width": 250, + "height": 100 + }, + { + "name": "lap", + "x": 2290, + "y": 44, + "width": 230, + "height": 100 } ], "track_region": { diff --git a/ocr.json b/ocr.json index cc8638c..cb59c47 100644 --- a/ocr.json +++ b/ocr.json @@ -1,101 +1,109 @@ { "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", - "//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", - "//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".", - "//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3", - "//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1", - "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", - "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", - "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", - "/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4", - "//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", + "//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5", + "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", + "//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0", + "//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5", + "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".", + "//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7", + "/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8", + "//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7", "////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".", - "//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3", - "/////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", + "////8H/wf/g/+D/8H/wf/g/+D/8H/4f/g//D/8H///8=": "/", "//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6", "//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9", - "//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5", - "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", - "/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2", - "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3", - "//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", - "//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2", - "//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5", - "//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6", - "/////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", + "//8P8AfgA8CBgcGDwYPBg8GDwYPBg4GBA8AH4A/w//8=": "0", + "////4P/wf/B/+D/4H/wf/B/+D/4H/wf/h/+D/8H///8=": "/", + "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", + "/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":", + "//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/A/8//8=": "1", + "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", + "/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2", + "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", "//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", + "//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/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0", - "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".", "////+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" } } \ No newline at end of file diff --git a/src/analysis.rs b/src/analysis.rs index 9246563..f15d18e 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -55,11 +55,14 @@ fn merge_with_max(a: &Option, b: &Option) -> Option { fn merge_frames(prev: &LapState, next: &LapState) -> LapState { LapState { 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), gas: merge_with_max(&prev.gas, &next.gas), tyres: merge_with_max(&prev.tyres, &next.tyres), lap_time: merge_with_max(&prev.lap_time, &next.lap_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() } } @@ -252,6 +255,7 @@ mod test { load_config_or_make_default("src/configs/config.default.json", "").unwrap(), ), ocr_db: Arc::new(OcrDatabase::load().unwrap()), + should_sample_ocr_data: true, ..Default::default() }; Arc::new(Mutex::new(state)) @@ -265,13 +269,16 @@ mod test { let lap_state = state.lock().unwrap().last_frame.as_ref().unwrap().clone(); 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!(79, lap_state.gas.unwrap()); assert_eq!(76, lap_state.tyres.unwrap()); assert!( - Duration::from_secs(24) <= lap_state.lap_time.unwrap() - && lap_state.lap_time.unwrap() <= Duration::from_secs(25) + Duration::from_secs(49) <= lap_state.lap_time.unwrap() + && lap_state.lap_time.unwrap() <= Duration::from_secs(50) ); } } diff --git a/src/configs/config.default.json b/src/configs/config.default.json index 9ceb643..3b82065 100644 --- a/src/configs/config.default.json +++ b/src/configs/config.default.json @@ -1,62 +1,77 @@ -{ - "ocr_regions": [ - { - "name": "lap", - "x": 2300, - "y": 46, - "width": 140, - "height": 90 - }, - { - "name": "health", - "x": 90, - "y": 1364, - "width": 52, - "height": 24 - }, - { - "name": "gas", - "x": 208, - "y": 1364, - "width": 52, - "height": 24 - }, - { - "name": "tyres", - "x": 325, - "y": 1364, - "width": 52, - "height": 24 - }, - { - "name": "best", - "x": 2325, - "y": 169, - "width": 183, - "height": 43 - }, - { - "name": "lap_time", - "x": 2325, - "y": 222, - "width": 183, - "height": 43 - } - ], - "track_region": { - "name": "track", - "x": 2020, - "y": 1030, - "width": 540, - "height": 410, - "threshold": 0.85 - }, - "penalty_orange_region": { - "name": "penalty", - "x": 989, - "y": 117, - "width": 30, - "height": 30 - }, - "track_recognition_threshold": 10 +{ + "ocr_regions": [ + { + "name": "health", + "x": 90, + "y": 1364, + "width": 52, + "height": 24, + "threshold": null, + "use_ocr_cache": null + }, + { + "name": "gas", + "x": 208, + "y": 1364, + "width": 52, + "height": 24, + "threshold": null, + "use_ocr_cache": null + }, + { + "name": "tyres", + "x": 325, + "y": 1364, + "width": 52, + "height": 24, + "threshold": null, + "use_ocr_cache": null + }, + { + "name": "best", + "x": 2325, + "y": 169, + "width": 183, + "height": 43, + "threshold": null, + "use_ocr_cache": null + }, + { + "name": "lap_time", + "x": 2325, + "y": 222, + "width": 183, + "height": 43, + "threshold": null, + "use_ocr_cache": null + }, + { + "name": "position", + "x": 50, + "y": 44, + "width": 250, + "height": 100 + }, + { + "name": "lap", + "x": 2290, + "y": 44, + "width": 230, + "height": 100 + } + ], + "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 } \ No newline at end of file diff --git a/src/configs/ocr.default.json b/src/configs/ocr.default.json index cc8638c..cb59c47 100644 --- a/src/configs/ocr.default.json +++ b/src/configs/ocr.default.json @@ -1,101 +1,109 @@ { "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", - "//8f+Afg5+fzz/Pf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", - "//////////8//B/4H/gf+B/4H/gf+D/8//////////8=": ".", - "//8H4Afg//P/+f/8f/w/4P/H/8//z//P4+cH4D/8//8=": "3", - "//8H4A/g/+P/4//j/+P/4//j/+P/4//j/+P/4//j//8=": "1", - "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", - "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", - "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", - "/////f/8f/x//j//n//P8+fz4/MBwAOA//P/8//z//8=": "4", - "//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", + "//8P8A/wD/CH/4f/B/gH8Afg/8H/wYfgA+AD+B/+//8=": "5", + "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", + "//8P+Afw4+fz5/HP+c/5z/nP+c/zx/Pnx/MP+H////8=": "0", + "//8P4A/gD+AP/4//D/gH4Afg/8H/wYfgA+AD8B/8//8=": "5", + "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".", + "//8BgAGAAYDhgeGB7cD/wH/gf+A/8D/wH/gP+A/87/8=": "7", + "/////w/wB+DH48fjB+AH4Afgw8PDw8PDB+AP8P////8=": "8", + "//8BgAGAAYDhgeGB/8D/wH/gP+A/8B/wH/gP+A/8//8=": "7", "////////////+D/wP/Af8A/wD/AP8B/4//////////8=": ".", - "//8D4APg//P/+f/8P/4/8P/H/8//z//P88cD8H////8=": "3", - "/////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", + "////8H/wf/g/+D/8H/wf/g/+D/8H/4f/g//D/8H///8=": "/", "//9/7x/AD+AH74f/g/AD4APAg8ODwwfDD8Af4H/7//8=": "6", "//8f+Afi8+fzz/PP48fHww/Y/8//z//v/+MH+D////8=": "9", - "//8HwAfAB8CD/wP/A+ADwAOA/4H/g+OBA4ABwAPw//8=": "5", - "//8f+Efi5+fzz/vf+9/73/vf+9/zz+PHx+MP8D/8//8=": "0", - "/////wfwA+DD4P/h/+H/4H/wP/gf/Af+B8AHwP////8=": "2", - "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8A/8//8=": "3", - "//8f+Afg5+fzz/vf+9/73/vf+9/zz+PHx+MP8H/+//8=": "0", - "//8P/APw++P/5//n/+f/8//4f/w//4//x/8DwAPA//8=": "2", - "//8P4A/g7//v/+//B/wH4P/P/8//3//P88cD8H/+//8=": "5", - "//8/gA+AB4AD34P/geABgAGAAYOBh4GHA4AHgA/g//8=": "6", - "/////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", + "//8P8AfgA8CBgcGDwYPBg8GDwYPBg4GBA8AH4A/w//8=": "0", + "////4P/wf/B/+D/4H/wf/B/+D/4H/wf/h/+D/8H///8=": "/", + "///f+w/wB+CDwcPDw8MHwA/AP8P/w0/gB/AH+F////8=": "9", + "/////w/wD/D//////////////////w/wD/AP8H/+//8=": ":", + "//8B/AH8AfwP/A/8D/wP/A/8D/wP/A/8D/wP/A/8//8=": "1", + "//8D4APg//P/+X/8f/4/+P/j/8//z//P+8cD8B/8//8=": "3", + "/////wfgA+DHwf/B/8H/4H/gP/gf/A/+B8ADwP////8=": "2", + "//8DgAOAA8D/4H/wH/AfwB+A/4H/g+OBA4ABwAPw//8=": "3", "//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", + "//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/wD+CH4cfDw8PDw8PDw8PHwwfgD/Af+H/+//8=": "0", - "//////////8//D/8H/gP8A/wH/g//D/8//////////8=": ".", "////+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" } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9a26d89..14404a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,6 +180,7 @@ fn show_race_state( ) { egui::Grid::new(format!("race:{}", race_name)).show(ui, |ui| { ui.label("Lap"); + ui.label("Position"); ui.label("Time"); ui.label("Δ Previous"); ui.label("Δ Best"); @@ -192,6 +193,7 @@ fn show_race_state( for (i, lap) in race.laps.iter_mut().enumerate() { if let Some(lap_time) = lap.lap_time { ui.label(format!("#{}", lap.lap.unwrap_or(i + 1))); + ui.label(format!("P{}", lap.position.unwrap_or_default())); if Some(lap_time) == fastest_lap { 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| { if let Some(frame) = &state.last_frame { 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.label(format!("Health: {}/100", frame.health.unwrap_or(0))); ui.label(format!("Gas: {}/100", frame.gas.unwrap_or(0))); diff --git a/src/ocr.rs b/src/ocr.rs index 989cf4d..1f92981 100644 --- a/src/ocr.rs +++ b/src/ocr.rs @@ -11,11 +11,15 @@ struct BoundingBox { 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 { for y in 0..image.height() { - let [r, g, b] = image.get_pixel(x, y).0; - if r < 100 && g < 100 && b < 100 { - return true; + if is_dark_pixel(image, x, y) { + return true } } 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 { for x in start_x..(start_x + width) { - let [r, g, b] = image.get_pixel(x, y).0; - if r < 100 && g < 100 && b < 100 { + if is_dark_pixel(image, x, y) { return true; } } @@ -37,9 +40,25 @@ fn take_while 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 { let mut x = 0; let mut boxes = Vec::new(); + let (cutoff_x, cutoff_y) = find_vertical_cutoff_from_right(image).unwrap_or_default(); while x < image.width() { 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 { let width = x - start_x; 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| { !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; - 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) }); let end_y = image.height() - inverse_y; @@ -114,22 +133,27 @@ pub fn compute_box_hashes(image: &RgbImage) -> Vec { hashes } -#[test] -fn test_bounding_boxes() { - let image_bytes = include_bytes!("test_data/test-montserrat.png"); - 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); -} +#[cfg(test)] +mod test { + use crate::ocr::{compute_box_hashes, get_character_bounding_boxes}; -#[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); + #[test] + fn test_bounding_boxes() { + let image_bytes = include_bytes!("test_data/test-montserrat.png"); + 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] + 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); + } } diff --git a/src/ocr_db.rs b/src/ocr_db.rs index 00c0dca..b8d8f5f 100644 --- a/src/ocr_db.rs +++ b/src/ocr_db.rs @@ -109,29 +109,39 @@ impl OcrDatabase { } } -#[test] -fn test_ocr() { - let raw: RawOcrDatabase = - serde_json::from_str(include_str!("configs/ocr.default.json")).unwrap(); - let db: OcrDatabase = (&raw).into(); +#[cfg(test)] +mod test { + use crate::ocr_db::{OcrDatabase, RawOcrDatabase}; - let image = image::load_from_memory(include_bytes!("test_data/test-time-1.png")) - .unwrap() - .to_rgb8(); - assert_eq!(db.ocr_image(&image), "00:30.625"); + #[test] + fn test_ocr() { + let raw: 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-2.png")) - .unwrap() - .to_rgb8(); - assert_eq!(db.ocr_image(&image), "00:20.296"); + let image = image::load_from_memory(include_bytes!("test_data/test-time-1.png")) + .unwrap() + .to_rgb8(); + assert_eq!(db.ocr_image(&image), "00:30.625"); - let image = image::load_from_memory(include_bytes!("test_data/test-num-1.png")) - .unwrap() - .to_rgb8(); - assert_eq!(db.ocr_image(&image), "1"); + let image = image::load_from_memory(include_bytes!("test_data/test-time-2.png")) + .unwrap() + .to_rgb8(); + assert_eq!(db.ocr_image(&image), "00:20.296"); - 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-num-1.png")) + .unwrap() + .to_rgb8(); + 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"); + } } diff --git a/src/state.rs b/src/state.rs index 810e396..8a030c4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -13,6 +13,10 @@ use crate::{config::Config, learned_tracks::LearnedTracks, ocr_db::OcrDatabase}; #[derive(Debug, Clone, Default)] pub struct LapState { pub lap: Option, + pub total_laps: Option, + + pub position: Option, + pub total_positions: Option, pub health: Option, pub gas: Option, @@ -52,10 +56,26 @@ fn parse_to_0_100(v: Option<&String>) -> Option { check_0_100(v?.parse::().ok()?) } +fn parse_with_slash(v: Option<&String>) -> (Option, Option) { + 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 { pub fn parse(raw: &HashMap) -> Self { + let (lap, total_laps) = parse_with_slash(raw.get("lap")); + let (position, total_positions) = parse_with_slash(raw.get("position")); Self { - lap: parse_to_0_100(raw.get("lap")), + lap, + total_laps, + position, + total_positions, health: parse_to_0_100(raw.get("health")), gas: parse_to_0_100(raw.get("gas")), tyres: parse_to_0_100(raw.get("tyres")), diff --git a/src/test_data/test-pos-1.png b/src/test_data/test-pos-1.png new file mode 100644 index 0000000..9a0f366 Binary files /dev/null and b/src/test_data/test-pos-1.png differ diff --git a/src/training_ui.rs b/src/training_ui.rs index 065831f..348d2eb 100644 --- a/src/training_ui.rs +++ b/src/training_ui.rs @@ -97,10 +97,15 @@ impl eframe::App for TrainingUi { ctx.set_visuals(Visuals::dark()); egui::CentralPanel::default().show(ctx, |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() { 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() { current_image.delete_data(); self.current_image_index += 1;