Edge Detection and filtering selected parts of image

I’m trying to develop an app that can detect the edges of shapes and then fill that shape with colour or certain patterns.

Something like a document scanner in that it will scan the shape and then instead of zoom and crop the documents I want to fill them with colour. Having a hard time going about it, anyone with any ideas?

I’ve tried to use edge detection and the a hough transform to find the shapes but I can’t really get anything to work.

Any advice is greatly accepted!