a few years ago I tried pattern matching with OpenCV, which is described here.
This worked very well, and I think this is what you are looking for; however, I remember that it was rather slow, so it may not be very convenient if you are programming a real-time application. If so, you may have to play around with the geometry of your shapes and try to find them using Hough transforms for lines and circles , both of which are implemented in OpenCV.
Good luck
source share