How can I define \"lower\" and \"upper\" range of two different color, such as red and blue (because red and blue are not next to each other in the HSV color)
This o
The below image shows the HSV Colour space, which works using Hue, Saturation & Value (or lightness).
When working in the HSV colour space it is important to remember this and that concepts such as Red & Green are a sort-of conversion back to a different data type.
Your upper and lower boundaries can therefore only be one point in this space but can include parts of the red and blue spectrum's, i.e. purple. You would need to select threshold values that meet the criteria of whatever processing output you need.
Either that or run two separate loops, the first to threshold out the Red, and the second to threshold out your blue and then blend the two images together using OpenCV Blend functions. See here for blending two colour spaces.