How to warp a bookshelf image with varying book sizes and colors?

I am currently working on a project that involves detecting book spines from bookshelf image using OpenCV.
I want to apply perspective transformation to the image and warp it, so it appears flat, this way I can detect lines for extracting spines. However, since the corner coordinates of the bookshelf may vary from image to image, I am a bit lost. I would be grateful for any insights, code snippets, or relevant documentation that you can share.
Thank you in advance for your help.

maybe …

let your app take the images, draw some guiding lines / markers into it, and let humans do the fine-tuning :]

I already thought about that, but I wanted to minimize user input other than taking the photo. If there are no other optimal solutions using opencv built-in functionalities, I will ask user to draw lines like you said.