简体   繁体   中英

How to merge overlapping rectangles in opencv C++?

I am trying to merge overlapping rectangles, represented as vector<Rect>

I am looking at the documentation here https://docs.opencv.org/3.4/d5/d54/group__objdetect.html for groupRectangles but it's not clear what the parameters (what is eps ?) are.

What is the easiest way to merge rectangles in opencv c++?

An example would be very helpful.

You can use the | union operator :

rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 )

rect |= rect1 (and the corresponding augmenting operations)

Given a vector of rectangles, the code below creates a single rectangle that contains all the others:

std::vector<cv::Rect> rects;
// fill rects....
cv::Rect final = rects[0];
for(const auto& r : rects) { final |= r; }

Eps parameter indicates how much intersection between the rectangle needs to be in order to merge them. For example, a 0.2 eps states that rectangles with more than 20% of overlapped area will be merged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM