The Martian Helmet Image is overlaid on the selfie using OpenCV's Haar Feature-based Cascade Classifiers to detect faces. The image is resized and padded with a border before being merged with the background using OpenCV's bitwise_and function. The resulting image is then saved back to the original file path, overwriting the original image. A Flask application is also built to handle incoming MMS/SMS requests from Twilio, which sends a selfie to be martianified when received.