The Google Camera app already does this (much). I look into this problem during a receipt scanning project. If you want development ideas look up "metric rectification" and 'manifold dewarping'; e.g. https://openaccess.thecvf.com/content/WACV2025/papers/Hertle...

Samsung Galaxy camera as well. Just hit "scan" when it pops up and you get the same results.

The "Initial Motivation" section in the article explains why existing mobile apps aren't good enough.