Auto / Manual Detect Document and Preview it with crop layer

Hello All, I am trying to build a Document scanner where I can manually / automatically detect Documents/receipts/letters from the camera and preview it with the respective crop layer just like VNDocumentCameraViewController does. Can someone guide me in the right direction or if anyone has any examples? I have gone through these WWDC links but didn't get good results.

https://developer.apple.com/videos/play/wwdc2021/10041/ https://developer.apple.com/videos/play/wwdc2019/234

Auto / Manual Detect Document and Preview it with crop layer
 
 
Q