What you are looking for is probably the BGR2HSV transformation. HSV is a color space where you can easily filter out a color you need. Under python the function to transform an image from BGR to HSV is called cv2.cvtColor
The function to filter your image for one set of Hue, Saturation and Value parameters is cv2.inRange
You need to find out the right Hue, Saturation and Value parameters for your color by testing, starting with values you get by converting the closest RGB color to what you need (red 0,0,255) to HSV and then tuning the values.
After filtering you will get an image with a blob of white pixels which represent the color. You can see an example here with a pink ball
in C++ it would look like that :
cv_bridge::CvImagePtr cv_ptr;
Mat HSVImage;
Mat ThreshImage;
// transform ROS image into OpenCV image
cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
//Transform the colors into HSV
cvtColor(cv_ptr->image,HSVImage,CV_BGR2HSV);
//for blue
inRange(HSVImage,Scalar(80,90,70),Scalar(110,125,200),ThreshImage);
here I found out that the blue of the ball I wanted the robot to track was between (80,90,70) and (110,125,200) HSV values.