Automatic analysis of scanned documents I highly recommend to see my blog post for better understanding: https://habr.com/ru/post/568990/