**Real-time Object Localization using Edge AI**
dev.to·20h·
Discuss: DEV
Flag this post

Real-time Object Localization using Edge AI

In this snippet, we utilize the OpenCV library to perform edge AI-based object localization using YOLO (You Only Look Once) algorithm on a Raspberry Pi:

import cv2
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
outputs = net.forward(frame)
boxes = []
for output in outputs:
for detection in output:
scores = detection[5:]
classID = np.argmax(scores)
confidence = scores[classID]
if confidence > 0.5 and classID == 0:  # 0 is the ID for the 'car' class in YOLOv3
box = detection[0:4] * np.array([frame.shape[1], frame.shape[0], frame.shape[1], frame.shape[0]])
(centerX, centerY, width, height) = box.astype("int")
x = int(centerX - (width / 2))
y = int(centerY - (height / 2...

Similar Posts

Loading similar posts...