If you add an image it'll be more clear.
I have only a C++ code to detect colors and draw bounding box search in the internet and you will find a lot of codes with Python doing the same job.
//===================== code ====================
if you want to detect yellow blocks you can test this :
//Convert your image to HSV
cvtColor(im, imHSV, COLOR_BGR2HSV);
//Select yellow part of the image
inRange(imHSV, Scalar(0, 208, 186), Scalar(47, 255, 255), mask1);
//Detect the contours of the yellow parts
vector<vector<Point>> contours; // Vector for storing contours
vector<Point> Ncontours;
// Find the contours in the image
findContours(mask1, contours, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
for (size_t i = 0; i < contours.size(); i++) // iterate through each contour.
{
double area = contourArea(contours[i]); // Find the area of contour
if (area > largest_area)
{
largest_area = area;
//Store the index of largest contour
largest_contour_index = i;
// Find the bounding rectangle for biggest contour
bounding_rect = boundingRect(contours[i]);
Ncontours = contours[i];
}
}
//In this code i serch the largest_area you can modifie the code to get all the contours present in you code