How to find the given rectangle co-ordinates are overlapped ?
How to group it together one if rectangles are overlapped?
Here given example Exmaple:
Format - Rect.x , Rect.y Rect.Width , Rect.Height
vector<Rect>boundRect(8);
boundRect[0].x = 260; boundRect[0].y = 77; boundRect[0].width = 90; boundRect[0].height = 150;
boundRect[1].x = 307; boundRect[1].y = 227; boundRect[1].width = 51; boundRect[1].height = 15;
boundRect[2].x = 358; boundRect[2].y = 214; boundRect[2].width = 41; boundRect[2].height = 51;
boundRect[3].x = 329; boundRect[3].y = 261; boundRect[3].width = 37; boundRect[3].height = 11;
boundRect[4].x = 204; boundRect[4].y = 272; boundRect[4].width = 241; boundRect[4].height = 146;
boundRect[5].x = 210; boundRect[5].y = 263; boundRect[5].width = 9; boundRect[5].height = 9;
boundRect[6].x = 184; boundRect[6].y = 362; boundRect[6].width = 32; boundRect[6].height = 64;
boundRect[7].x = 551; boundRect[7].y = 345; boundRect[7].width = 27; boundRect[7].height = 25;
The above are the co-ordinates , we need to find which rectangle are overlapped and group it.
#include "opencv2/opencv.hpp"
#include <string>
using namespace cv;
using namespace std;
int main()
{
int nA_Val = 3;
int nMax_Val = 150;
Mat mImage = imread("TButterfly.jpg",1);
floodFill(mImage,cv::Point(71,62),cv::Scalar(0,0,255),0,cv::Scalar(nA_Val,nA_Val,nA_Val),cv::Scalar(nMax_Val,nMax_Val,nMax_Val),4);
erode(mImage,mImage,Mat());
imshow("mImage",mImage);
imwrite("mImage.jpg",mImage);
waitKey(0);
return 0;
}