By processing a time series graph, I Would like to detect patterns that look similar to this:

Using a sample time series as an example, I would like to be able to detect the patterns as marked here:

What kind of AI algorithm (I am assuming marchine learning techniques) do I need to use to achieve this? Is there any library (in C/C++) out there that I can use?