Views
No views yet
| Property | Value |
|---|---|
| Category | Object Classification (Traffic Categorization: People / Vehicles) |
| Base Model | YOLO26 (Ultralytics) |
| Source Framework | PyTorch (Ultralytics) |
| Supported Precisions | FP32, FP16, INT8 (mixed-precision) |
| Inference Engine | OpenVINO |
| Hardware | CPU, GPU, NPU |
| Detected Class(es) | person and vehicle classes grouped into People and Vehicles |
People and Vehicles, so operators get an at-a-glance picture of a scene.person class.bicycle, car, motorcycle, bus, train, and truck classes.yolo26n, yolo26s, yolo26m, yolo26l, yolo26x.
Smaller variants (yolo26n, yolo26s) are recommended for high-FPS edge deployment; larger variants improve recall for small objects.1python3 -m venv .venv --system-site-packages
2source .venv/bin/activateNote: The--system-site-packagesflag is required so the virtual environment can access the system-installed OpenVINO and DLStreamer Python packages.
1chmod +x export_and_quantize.sh
2./export_and_quantize.sh1./export_and_quantize.sh yolo26n FP32 # full-precision
2./export_and_quantize.sh yolo26n INT8 # quantized
3./export_and_quantize.sh yolo26s # larger variant, default FP16yolo26n with any variant (yolo26s, yolo26m, yolo26l, yolo26x).
The second argument selects the precision (FP32, FP16, INT8); the default is FP16.openvino, ultralytics; adds nncf for INT8).test_video.mp4) of an urban roundabout at low resolution (640x360).yolo26n_openvino_model/ -- FP32 or FP16 OpenVINO IR model directory.yolo26n_objcls_int8.xml / yolo26n_objcls_int8.bin -- INT8 quantized model (only when INT8 is selected).| Precision | CPU | GPU | NPU |
|---|---|---|---|
| FP32 | Yes | Yes | No |
| FP16 | Yes | Yes | Yes |
| INT8 | Yes | Yes | Yes |
Note: The INT8 calibration uses a frame from the bundled sample video. For production accuracy, replace it with a representative set of frames from the target deployment site.
People or Vehicles category, draws boxes colored per
category, overlays live category counts, and writes the annotated result to
output_openvino.mp4.
YOLO26 is end-to-end (NMS-free), so no manual non-maximum suppression is needed.
Change the device string to run on CPU, GPU, or NPU.1import cv2
2import numpy as np
3import openvino as ov
4
5CONF_THRESHOLD = 0.4
6INPUT_SIZE = 640
7
8# Map the traffic-relevant COCO class ids into higher-level city categories.
9# People and Vehicles are the two categories tracked for situational awareness.
10CATEGORY_BY_CLASS_ID = {
11 0: "People", # person
12 1: "Vehicles", # bicycle
13 2: "Vehicles", # car
14 3: "Vehicles", # motorcycle
15 5: "Vehicles", # bus
16 6: "Vehicles", # train
17 7: "Vehicles", # truck
18}
19# BGR overlay colors for each category.
20CATEGORY_COLORS = {
21 "People": (0, 200, 0),
22 "Vehicles": (255, 128, 0),
23}
24
25core = ov.Core()
26model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
27
28# YOLO26 embeds the 80 COCO class names in rt_info. Ultralytics separates
29# multi-word names with underscores (e.g. "traffic_light"), so restore spaces.
30COCO_NAMES = [
31 name.replace("_", " ")
32 for name in model.get_rt_info()["model_info"]["labels"].value.split()
33]
34
35# Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
36compiled = core.compile_model(model, "CPU")
37output_port = compiled.output(0)
38
39cap = cv2.VideoCapture("test_video.mp4")
40fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
41width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
42height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
43writer = cv2.VideoWriter(
44 "output_openvino.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height)
45)
46
47totals = {"People": 0, "Vehicles": 0}
48frame_idx = 0
49while True:
50 ok, frame = cap.read()
51 if not ok:
52 break
53 frame_idx += 1
54
55 blob = cv2.resize(frame, (INPUT_SIZE, INPUT_SIZE))
56 blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
57 blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
58
59 # YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id].
60 output = compiled([blob])[output_port][0]
61
62 sx, sy = width / INPUT_SIZE, height / INPUT_SIZE
63 counts = {"People": 0, "Vehicles": 0}
64 for x1, y1, x2, y2, conf, class_id in output:
65 if conf < CONF_THRESHOLD:
66 continue
67 category = CATEGORY_BY_CLASS_ID.get(int(class_id))
68 if category is None:
69 continue # not a traffic-relevant object
70 counts[category] += 1
71 totals[category] += 1
72 color = CATEGORY_COLORS[category]
73 px1, py1 = int(x1 * sx), int(y1 * sy)
74 px2, py2 = int(x2 * sx), int(y2 * sy)
75 label = f"{category}: {COCO_NAMES[int(class_id)]} {conf:.2f}"
76 cv2.rectangle(frame, (px1, py1), (px2, py2), color, 2)
77 cv2.putText(frame, label, (px1, py1 - 5),
78 cv2.FONT_HERSHEY_SIMPLEX, 2.0, color, 2)
79
80 # Overlay the per-category counts for this frame.
81 banner = f"People: {counts['People']} Vehicles: {counts['Vehicles']}"
82 cv2.rectangle(frame, (0, 0), (width, 60), (0, 0, 0), -1)
83 cv2.putText(frame, banner, (15, 45),
84 cv2.FONT_HERSHEY_SIMPLEX, 2.0, (255, 255, 255), 2)
85
86 if frame_idx % 30 == 0:
87 print(f"frame {frame_idx}: {banner}", flush=True)
88
89 writer.write(frame)
90
91cap.release()
92writer.release()
93print(f"Summary: People={totals['People']} Vehicles={totals['Vehicles']}")
94print("Saved: output_openvino.mp4")"CPU" -- default, works on all Intel platforms."GPU" -- Intel integrated or discrete GPU."NPU" -- Intel NPU (validate with benchmark_app -d NPU).export_and_quantize.sh script downloads test_video.mp4 automatically.
Re-run the OpenVINO sample above.
The script reads test_video.mp4, prints the running People and Vehicles counts to the console, and writes the annotated video to output_openvino.mp4.1frame 30: People: 4 Vehicles: 6
2frame 60: People: 3 Vehicles: 7
3frame 90: People: 5 Vehicles: 5
4Summary: People=372 Vehicles=548
5Saved: output_openvino.mp4
gvadetect, overlays bounding boxes with gvawatermark for the traffic-relevant
classes only (non-traffic detections such as handbag are filtered out via
show-roi), saves the annotated result to output_dlstreamer.mp4, and prints the
People and Vehicles category counts per frame from the detection metadata.Notes on running this sample:
Use the FP16 IR (yolo26n_openvino_model/yolo26n.xml). Class names are read automatically from the model's embeddedmetadata.yamlby DLStreamer 2026.0+ -- no externallabels-fileis required. ExportPYTHONPATHso the DLStreamer Python module is importable:bash1source /opt/intel/openvino_2026/setupvars.sh 2source /opt/intel/dlstreamer/scripts/setup_dls_env.sh 3export PYTHONPATH=/opt/intel/dlstreamer/python:\ 4/opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
1import gi
2
3gi.require_version("Gst", "1.0")
4gi.require_version("GstAnalytics", "1.0")
5from gi.repository import Gst, GLib, GstAnalytics
6
7Gst.init([])
8
9INPUT_VIDEO = "test_video.mp4"
10
11# Traffic-relevant COCO labels grouped into higher-level city categories.
12CATEGORY_BY_LABEL = {
13 "person": "People",
14 "bicycle": "Vehicles",
15 "car": "Vehicles",
16 "motorcycle": "Vehicles",
17 "bus": "Vehicles",
18 "train": "Vehicles",
19 "truck": "Vehicles",
20}
21
22# For CPU: change device=GPU to device=CPU.
23# For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
24# gvawatermark displ-cfg:
25# show-roi=... draws only the traffic-relevant classes (person + vehicles),
26# so non-traffic detections such as handbag/backpack are not boxed.
27# font-scale=1.5 enlarges the label text for better visualization.
28pipeline_str = (
29 f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
30 "videoconvert ! "
31 "gvadetect model=yolo26n_openvino_model/yolo26n.xml "
32 "device=GPU "
33 "threshold=0.4 ! queue ! "
34 "gvawatermark "
35 "displ-cfg=show-roi=person:bicycle:car:motorcycle:bus:train:truck,font-scale=2.5 ! "
36 "videoconvert ! video/x-raw,format=I420 ! "
37 "openh264enc ! h264parse ! "
38 "mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
39)
40pipeline = Gst.parse_launch(pipeline_str)
41
42totals = {"People": 0, "Vehicles": 0}
43
44
45def on_buffer(pad, info):
46 buf = info.get_buffer()
47 rmeta = GstAnalytics.buffer_get_analytics_relation_meta(buf)
48 if rmeta is None:
49 return Gst.PadProbeReturn.OK
50 counts = {"People": 0, "Vehicles": 0}
51 idx = 1
52 while True:
53 ok, od = rmeta.get_od_mtd(idx)
54 if not ok:
55 break
56 label = GLib.quark_to_string(od.get_obj_type())
57 category = CATEGORY_BY_LABEL.get(label)
58 if category is not None:
59 counts[category] += 1
60 totals[category] += 1
61 idx += 1
62 if counts["People"] or counts["Vehicles"]:
63 print(f"frame: People={counts['People']} Vehicles={counts['Vehicles']}",
64 flush=True)
65 return Gst.PadProbeReturn.OK
66
67
68sink = pipeline.get_by_name("sink")
69sink_pad = sink.get_static_pad("sink")
70sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
71
72pipeline.set_state(Gst.State.PLAYING)
73bus = pipeline.get_bus()
74bus.timed_pop_filtered(
75 Gst.CLOCK_TIME_NONE,
76 Gst.MessageType.EOS | Gst.MessageType.ERROR,
77)
78pipeline.set_state(Gst.State.NULL)
79print(f"Summary: People={totals['People']} Vehicles={totals['Vehicles']}")
device=GPU -- default in the sample code.device=CPU -- change device=GPU to device=CPU.device=NPU -- change device=GPU to device=NPU; use batch-size=1 and nireq=4 for best NPU utilization.