I have no idea how to do image recognition, but I have to extract the red-outlined portion from below image and read the graph, supposing the following:
1 – Off Duty
2 – Sleeper Berth
3 – Driving
4 – On Duty
My program should read the graph and, in this example, show a result of 333333333111111222222222444444

Assuming there are no alignment issues, you could divide the task as follows