Skip to content

Commit 1698e5d

Browse files
committed
Update ReadMe.
1 parent 62fc26d commit 1698e5d

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

ReadMe.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,50 @@
11
# IOU
22

3-
Intersection over Union.
4-
By WeiQM.
3+
This is a C++ implement of intersection over union (IoU) ratio calculation, which requires no third-party libraries. And the IoU calculation method is applicable to rectangles, rotated rectangles and any convex polygon. A test demo is also included, which can verify the validity and accuracy of the IoU calculation method.
4+
5+
---
6+
7+
## About the IoU calculation method
8+
9+
Given two convex polygons `Q1` and `Q2`, the IoU ration of `Q1` and `Q2` is estimated as:
10+
11+
```
12+
Area(Q1+Q2) = Area(Q1) + Area(Q2) - Area(Q1*Q2)
13+
IoU = Area(Q1*Q2) / Area(Q1+Q2)
14+
'+' means union;
15+
'*' means intersection.
16+
```
17+
18+
### Area of a convex polygon
19+
20+
The convex polygon is decomposed into a group of triangles, which are non-overlapping and complementary. The area of the convex polygon is equal to the sum of all the triangular areas.
21+
22+
![image](http://github.com/CheckBoxStudio/IoU/raw/master/images/triangles.png)
23+
24+
### Intersection of two convex polygons
25+
26+
The intersection of two convex polygons is also a convex polygon, which consists of two types of vertexes, i.e., a) the intersection points of edges of the two convex polygons and b) the own vertices of the some polygon which are located inside the other convex polygon. Once all these points are found, the intersection of two convex polygons is obtained. And the area of the intersection, treated as a convex polygon, can then be calculated.
27+
28+
![image](http://github.com/CheckBoxStudio/IoU/raw/master/images/iou.png)
29+
30+
### Area of union of two polygons
31+
32+
The area of the union of two polygons is equal to the sum of the areas of the polygon minus the area of its intersection.
33+
34+
```
35+
Area(Q1+Q2) = Area(Q1) + Area(Q2) - Area(Q1*Q2)
36+
37+
'+' means union;
38+
'*' means intersection.
39+
```
40+
41+
---
42+
43+
## About the test demo
44+
45+
In the test demo, a black background image `I` is first generated, and two convex polygons `Q1` and `Q2` are then randomly generated. `Q1` is drawn on `I` in Red-channel, and `Q2` is drawn in Blue-channel. Namely, the region of `Q1` is in Red, and the region of `Q2` is in Blue, while the intersection region of `Q1` and `Q2` is in Magenta. The areas of `Q1`, `Q2`, intersection of `Q1` and `Q2`, union of `Q1` and `Q2` can be calculated by directly counting the number of pixels with different colors, and the IoU ratio is further calculated. Such values, calculated by counting, is compared to the values that are given by the IoU calculation method.
46+
47+
Noted that [OpenCV](https://opencv.org/) is required for dealing with the images in the test demo.
48+
49+
---
50+
By [WeiQM](https://weiquanmao.github.io) at D409.IPC.BUAA.

images/iou.png

25.4 KB
Loading

images/triangles.png

25 KB
Loading

test/test.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/***********************************
2+
* test.h
3+
*
4+
* Test demo of iou.
5+
*
6+
* Author: WeiQM (weiquanmao@hotmail.com)
7+
* Github: https://github.com/CheckBoxStudio/IoU
8+
*
9+
* 2018
10+
***********************************/
111
#ifndef _IOU_TEST_H_FILE_
212
#define _IOU_TEST_H_FILE_
313

0 commit comments

Comments
 (0)