本文介绍了如何找到给定的矩形坐标是重叠的,如何将它们组合成一个如果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何找到给定的矩形坐标重叠? 如果矩形重叠,如何将它组合在一起? 这里给出了示例Exmaple: 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); //cv::floodFill(mImage, cv::Point(150,150), cv::Scalar(255.0, 255.0, 255.0)); //Mat mask = imread("Mask2.jpg",0); //cv::Mat mask = cv::Mat::zeros(mImage.rows + 2, mImage.cols + 2, CV_8U); // Mat mIMask = imread("",1); // floodFill(mImage,cv::Point(55,70),cv::Scalar(0,0,255),0,cv::Scalar(nA_Val,nA_Val,nA_Val),cv::Scalar(nMax_Val,nMax_Val,nMax_Val),4);// cv::floodFill(mImage, mask, cv::Point(210,148), cv::Scalar(0,0,255), 0, cv::Scalar(nA_Val,nA_Val,nA_Val),// cv::Scalar(nMax_Val,nMax_Val,nMax_Val), 4 + (255 << 8) + cv::FLOODFILL_FIXED_RANGE );// cv::floodFill(mImage, mask, cv::Point(404,231), cv::Scalar(0,255,255), 0, cv::Scalar(nA_Val,nA_Val,nA_Val),// cv::Scalar(nMax_Val,nMax_Val,nMax_Val), 4 + (255 << 8) + cv::FLOODFILL_FIXED_RANGE ); 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); // floodFill(mImage,cv::Point(202,350),cv::Scalar(0,255,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;} 解决方案 这篇关于如何找到给定的矩形坐标是重叠的,如何将它们组合成一个如果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 06:53