This program calculates the area of two bounding boxes and checks if a point is inside each box.
import torch
# Define bounding boxes: [x_min, y_min, x_max, y_max]
boxes = torch.tensor([[10, 20, 50, 60], [30, 40, 70, 80]])
# Function to compute area of bounding boxes
def box_area(boxes):
widths = boxes[:, 2] - boxes[:, 0]
heights = boxes[:, 3] - boxes[:, 1]
return widths * heights
# Compute areas
areas = box_area(boxes)
print(f"Areas of bounding boxes: {areas.tolist()}")
# Function to check if a point is inside a bounding box
# point: (x, y), box: [x_min, y_min, x_max, y_max]
def is_point_in_box(point, box):
x, y = point
return (box[0] <= x <= box[2]) and (box[1] <= y <= box[3])
# Test point
point = (35, 50)
inside_results = [is_point_in_box(point, box) for box in boxes]
print(f"Is point {point} inside each box? {inside_results}")