1 | initial version |
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; findContours(mask1, contours, RETR_CCOMP, CHAIN_APPROX_SIMPLE); // Find the contours in the image
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;
largest_contour_index = i; //Store the index of largest contour
bounding_rect = boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
Ncontours = contours[i];
}
}
//In this code i serch the largest_area you cab modifie the code to get all the contours present in you code
2 | No.2 Revision |
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
3 | No.3 Revision |
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====================
//===================== 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;
findContours(mask1, contours, RETR_CCOMP, CHAIN_APPROX_SIMPLE); // Find the contours in the image
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;
largest_contour_index = i; //Store the index of largest contour
bounding_rect = boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
Ncontours = contours[i];
}
}
//In this code i serch the largest_area you cab modifie the code to get all the contours present in you code
4 | No.4 Revision |
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);
mask1);
//Detect the contours of the yellow parts
vector<vector<Point>> contours; // Vector for storing contours
vector<Point> Ncontours;
findContours(mask1, contours, RETR_CCOMP, CHAIN_APPROX_SIMPLE); // Find the contours in the image
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;
largest_contour_index = i; //Store the index of largest contour
bounding_rect = boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
Ncontours = contours[i];
}
}
//In this code i serch the largest_area you cab modifie the code to get all the contours present in you code
5 | No.5 Revision |
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); // Find the contours in the image
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;
largest_contour_index = i; //Store the index of largest contour
bounding_rect = boundingRect(contours[i]); largest_contour_index = i;
// Find the bounding rectangle for biggest contour
contour
bounding_rect = boundingRect(contours[i]);
Ncontours = contours[i];
}
}
//In this code i serch the largest_area you cab modifie the code to get all the contours present in you code
6 | No.6 Revision |
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 cab can modifie the code to get all the contours present in you code