# Examples of IOU calculation in Python computer vision

Time：2020-9-18

Where x1, Y1; X2, Y2 represent the center points of the two rectangular frames respectively

``````
def calcIOU(x1, y1, w1, h1, x2, y2, w2, h2):
if((abs(x1 - x2) < ((w1 + w2)/ 2.0)) and (abs(y1-y2) < ((h1 + h2)/2.0))):
left = max((x1 - (w1 / 2.0)), (x2 - (w2 / 2.0)))
upper = max((y1 - (h1 / 2.0)), (y2 - (h2 / 2.0)))

right = min((x1 + (w1 / 2.0)), (x2 + (w2 / 2.0)))
bottom = min((y1 + (h1 / 2.0)), (y2 + (h2 / 2.0)))

inter_w = abs(left - right)
inter_h = abs(upper - bottom)
inter_square = inter_w * inter_h
union_square = (w1 * h1)+(w2 * h2)-inter_square

calcIOU = inter_square/union_square * 1.0
print("calcIOU:", calcIOU)
else:
print("No intersection!")

return calcIOU
def main():
calcIOU(1, 2, 2, 2, 2, 1, 2, 2)

if __name__ == '__main__':
main()``````

The above example of IOU calculation in Python computer vision is the whole content shared by Xiaobian. I hope to give you a reference, and I hope you can support developeppaer more.

## Understand mybatis step by step through the project

Reprint please be sure to indicate the source, original is not easy! Related articles:Understand mybatis < 1 > step by step through the project All code address of the project:Github-Mybatis Mybatis solves the problem of JDBC programming 1. The frequent creation and release of database links results in the waste of system resources, which affects […]