Object detection identifies and locates objects within images using bounding boxes.
Introduction to AI
What is AI?
Machine Learning Basics
How Machine Learning Works
AI Applications
AI in the Real World
Reinforcement Learning
Reinforcement Learning Basics
AI
Intermediate
FREE
Object Detection
Lesson 2 of 17
Intermediate
Interactive
Syntax
AI
from ultralytics import YOLO
model = YOLO('yolov8n.pt')
results = model('image.jpg')
results[0].show()
Bounding Box Concept
PYTHON
# Object detection concept def calculate_iou(box1, box2): x1 = max(box1[0], box2[0]) y1 = max(box1[1], box2[1]) x2 = min(box1[2], box2[2]) y2 = min(box1[3], box2[3]) intersection = max(0, x2 - x1) * max(0, y2 - y1) area1 = (box1[2] - box1[0]) * (box1[3] - box1[1]) area2 = (box2[2] - box2[0]) * (box2[3] - box2[1]) union = area1 + area2 - intersection return intersection / union if union > 0 else 0 box1 = [10, 10, 50, 50] # x1, y1, x2, y2 box2 = [30, 30, 70, 70] print(f"IoU: {calculate_iou(box1, box2):.2f}")
Practice
1
Exercise
Practice this concept.
Answer
Write the code as shown above.
Quick Quiz
1
What did you learn?
This covers the basics.
Interview Questions
It is a fundamental AI feature.