Streaming Cameras with YOLOv8
Apache NiFi, Python, YoLoV8, MinIO, S3, Images, Cameras, New York City
We can add a very easy to run Ultralytics YOLO v8 to hit against ingested camera’s from New York City. As you can see the code is really simple, we just need to load the pretrained model and call predict with some parameters and the image.
from ultralytics import YOLO
import sys
import io
import shutil
shutil.rmtree('runs/detect')
# Load a model
model = YOLO('yolov8n.pt') # pretrained YOLOv8n model
source = sys.argv[1]
results = model.predict(source, stream=False, save=True, imgsz=320, conf=0.5)
for r in results:
print(r.tojson())
Output
[
{
"name": "car",
"class": 2,
"confidence": 0.5163618922233582,
"box": {
"x1": 188.54917907714844,
"y1": 141.74185180664062,
"x2": 204.51304626464844,
"y2": 154.35519409179688
}
}
]
NiFi Flow
NiFi Detailed Steps
We invoke an HTTP URL from NY Open Data to get a list of all URLs. We send the metadata to a Kafka topic. We call the webcam URL to get the image. We save it to MinIO. We then save it local in a temporary file to get it analyzed by YOLOv8. We then retrieve the augmented image and send it to Slack.
META DATA
{
"Latitude" : 41.51472,
"Longitude" : -74.0733,
"ID" : "Skyline-9873",
"Name" : "I-87 MP 060.40 NB Just North of Interchange 17 (Newburgh/I-84)",
"DirectionOfTravel" : "Northbound",
"RoadwayName" : "I-87 - NYS Thruway",
"Url" : "https://511ny.org/map/Cctv/9873--43",
"VideoUrl" : "https://s58.nysdot.skyvdn.com:443/rtplive/TA_046/playlist.m3u8",
"Disabled" : false,
"Blocked" : false
}