I don’t think it would be possible to find a heuristic or algorithm to detect facial expressions. I would approach it with machine learning. Then the problem is where to find material to teach machine learning algorithm? Material would consist of set of images and related expression (classification). Neural networks would be in a way easiest method, but it would need lot’s of annotated material (data with classifications). Other machine learning algorithm could be used and they don’t require nearly as much teaching material. But they will not be able to learn straight from images. Those image would need to be transformed a to much smaller set of numbers. I believe biometric face recognition is based on

Blockquote
Some face recognition algorithms identify facial features by extracting landmarks, or features, from an image of the subject’s face. For example, an algorithm may analyze the relative position, size, and/or shape of the eyes, nose, cheekbones, and jaw.[14] These features are then used to search for other images with matching features.https://en.wikipedia.org/wiki/Facial_recognition_system#Traditional

Anyway there are methods to reduce faces and expression to a smaller set of number where simpler machine learning methods like Support Vector Machine could work well.

This is a very difficult problem, but it’s subject of active research. So if you want to proceed search internet. Face detection would be a good starting point.