Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

calculate iou of two rectangles

from shapely.geometry import Polygon
""" Assuming two rectangle with the following corner points:
box_1 = [[x_1, y_1], [x_2, y_1], [x_2,y_2], [x_1,y_2]]
box_2 = [[x_1, y_1], [x_2, y_1], [x_2,y_2], [x_1,y_2]]
(x_1,y_1)+---- +(x_2,y_1)
         |box_1|   
(x_1,y_2)+-----+(x_2,y_2)"""

def calculate_iou(box_1, box_2):
    poly_1 = Polygon(box_1)
    poly_2 = Polygon(box_2)
    iou = poly_1.intersection(poly_2).area / poly_1.union(poly_2).area
    return iou


box_1 = [[511, 41], [577, 41], [577, 76], [511, 76]]
box_2 = [[544, 59], [610, 59], [610, 94], [544, 94]]

print(calculate_iou(box_1, box_2))
Comment

PREVIOUS NEXT
Code Example
Python :: numerical columns 
Python :: post to get 
Python :: How to Add Elements to a dictionary using the update() method 
Python :: How to Loop Through Tuples using while loop in python 
Python :: python equivalent linkedhashmap 
Python :: python math.factorial algorithm 
Python :: how to use print function in python stack overflow 
Python :: Plot Multiple ROC Curves in Python 
Python :: Create An Empty List(Array) In Python 
Python :: immutabledict working 
Python :: python Pandas - Analyzing DataFrames 
Python :: convert set to list python time complexity method 2 
Python :: Function argument unpacking in python 
Python :: Reading Excel and other Microsoft Office files 
Python :: split string and remove some and re-create again 
Python :: enumerate for string 
Python :: way to close file python with staement 
Python :: python basic programs quadratic equation 
Python :: python merge file 
Python :: how to download a website using python 
Python :: preventing players from changing existing entries in tic tac toe game 
Python :: internet spam 
Python :: Python Textfeld lköschen 
Python :: python beacon 
Python :: install sort 
Python :: python numpy read from stdin 
Python :: sqlalchemy create engine SQLite Relative 
Python :: python local variable 
Python :: Python match.start(), match.end() 
Python :: json to csv python github 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =