1 | initial version |

cv::Rect has union / intersection operators:

union : `rect1 | rect2`

intersection: `rect1 & rect2`

here's an example:

Rect A(20,20,80,80); Rect B(60,60,60,60);

Rect C = A & B; Rect D = A | B;

cerr << "A" << A << endl; cerr << "B" << B << endl; cerr << "C" << C << endl; cerr << "D" << D << endl;

Mat draw(200,200,CV_8UC3,Scalar::all(0)); rectangle(draw,A,Scalar(200,0,0),2); rectangle(draw,B,Scalar(200,0,0),2); rectangle(draw,C,Scalar(0,0,200),1); rectangle(draw,D,Scalar(0,200,0),1);

A[80 x 80 from (20, 20)] B[60 x 60 from (60, 60)] C[40 x 40 from (60, 60)] D[100 x 100 from (20, 20)]

2 | No.2 Revision |

cv::Rect has union / intersection operators:

union : `rect1 | rect2`

intersection: `rect1 & rect2`

here's an example:

```
Rect A(20,20,80,80);
Rect
```~~B(60,60,60,60);~~B(60,60,60,60);
~~ ~~Rect C = A & B;
Rect D = A | ~~B;~~

B;
~~ ~~cerr << "A" << A << endl;
cerr << "B" << B << endl;
cerr << "C" << C << endl;
cerr << "D" << D << ~~endl;~~

endl;
~~ ~~Mat draw(200,200,CV_8UC3,Scalar::all(0));
rectangle(draw,A,Scalar(200,0,0),2);
rectangle(draw,B,Scalar(200,0,0),2);
rectangle(draw,C,Scalar(0,0,200),1);
~~rectangle(draw,D,Scalar(0,200,0),1);~~

rectangle(draw,D,Scalar(0,200,0),1);

```
A[80 x 80 from (20, 20)]
B[60 x 60 from (60, 60)]
C[40 x 40 from (60, 60)]
D[100 x 100 from (20,
```~~20)]~~20)]

3 | No.3 Revision |

cv::Rect has union / intersection operators:

union : `rect1 | rect2`

intersection: `rect1 & rect2`

here's an example:

`Rect `~~A(20,20,80,80);
~~A(20,20,80,80); // blue
Rect ~~B(60,60,60,60);
~~B(60,60,60,60); // blue
Rect C = A & ~~B;
~~B; // red
Rect D = A | ~~B;
~~B; // green
cerr << "A" << A << endl;
cerr << "B" << B << endl;
cerr << "C" << C << endl;
cerr << "D" << D << endl;
Mat draw(200,200,CV_8UC3,Scalar::all(0));
rectangle(draw,A,Scalar(200,0,0),2);
rectangle(draw,B,Scalar(200,0,0),2);
rectangle(draw,C,Scalar(0,0,200),1);
rectangle(draw,D,Scalar(0,200,0),1);

```
A[80 x 80 from (20, 20)]
B[60 x 60 from (60, 60)]
C[40 x 40 from (60, 60)]
D[100 x 100 from (20, 20)]
```

4 | No.4 Revision |

cv::Rect has union / intersection operators:

union : `rect1 | rect2`

intersection: `rect1 & rect2`

here's an example:

```
Rect A(20,20,80,80); // blue
Rect B(60,60,60,60); // blue
Rect C = A & B; // red
Rect D = A | B; // green
cerr << "A" << A << endl;
cerr << "B" << B << endl;
cerr << "C" << C << endl;
cerr << "D" << D << endl;
Mat draw(200,200,CV_8UC3,Scalar::all(0));
rectangle(draw,A,Scalar(200,0,0),2);
rectangle(draw,B,Scalar(200,0,0),2);
rectangle(draw,C,Scalar(0,0,200),1);
rectangle(draw,D,Scalar(0,200,0),1);
```

```
A[80 x 80 from (20, 20)]
B[60 x 60 from (60, 60)]
C[40 x 40 from (60, 60)]
D[100 x 100 from (20, 20)]
```

now, to find out, if 2 Rects overlap, just check the area of the intersection:

```
bool intersects = ((A & B).area() > 0);
```

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.