I want to use Oak-d Pro to object tracking on IR camera with my model, I used Depthai Tools to change .pt into blob format,The option show that yolov8 is detect only, I am not sure it is the reason why my tracking program can't tracking object correctly, Please told me how to transfer my model into blob also can tracking
This is my tracking code, Can run ,but can't be recognized and tracked correctly
import cv2
import depthai as dai
import numpy as np
import argparse # Import the argparse package for handling command line arguments
from pathlib import Path # Import the Path object for handling paths
import time
# Define object class labels
labelMap = ["egg"]
# Set the path to the MobileNet SSD model
nnPathDefault = str((Path(__file__).parent / Path("C:/egg.blob")).resolve().absolute())
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('nnPath', nargs='?', help="Path to mobilenet detection network blob", default=nnPathDefault)
parser.add_argument('-ff', '--full_frame', action="store_true", help="Perform tracking on full RGB frame", default=False)
args = parser.parse_args()
# Check if full frame tracking is enabled
fullFrameTracking = args.full_frame
# Create a pipeline
pipeline = dai.Pipeline()
monoL = pipeline.create(dai.node.MonoCamera)
manip = pipeline.create(dai.node.ImageManip)
manipOut = pipeline.create(dai.node.XLinkOut)
detectionNetwork = pipeline.create(dai.node.MobileNetDetectionNetwork)
objectTracker = pipeline.create(dai.node.ObjectTracker)
trackerOut = pipeline.create(dai.node.XLinkOut)
manipOut.setStreamName('flood-left')
trackerOut.setStreamName("tracklets")
monoL.setNumFramesPool(24)
monoL.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript("""
floodBright = 0.1
LOGGING = False # Set to `True` for latency/timings debugging
node.warn(f'IR drivers detected: {str(Device.getIrDrivers())}')
while True:
# Wait first for a frame event, received at MIPI start-of-frame
event = node.io['event'].get()
if LOGGING: tEvent = Clock.now()
# Set IR flood light intensity
Device.setIrFloodLightIntensity(floodBright)
if LOGGING: tIrSet = Clock.now()
# Wait for the actual frame (after MIPI capture and ISP proc is done)
frameL = node.io['frameL'].get()
if LOGGING: tLeft = Clock.now()
if LOGGING:
latIR = (tIrSet - tEvent ).total_seconds() * 1000
latEv = (tEvent - event.getTimestamp() ).total_seconds() * 1000
latProcL = (tLeft - event.getTimestamp() ).total_seconds() * 1000
node.warn(f'T[ms] latEv:{latEv:5.3f} latIR:{latIR:5.3f} latProcL:{latProcL:6.3f}')
node.io['floodL'].send(frameL)
""")
# Model-specific settings
detectionNetwork.setBlobPath(args.nnPath)
detectionNetwork.setConfidenceThreshold(0.85)
detectionNetwork.input.setBlocking(False)
objectTracker.setDetectionLabelsToTrack([0])
objectTracker.setTrackerType(dai.TrackerType.ZERO_TERM_COLOR_HISTOGRAM)
objectTracker.setTrackerIdAssignmentPolicy(dai.TrackerIdAssignmentPolicy.SMALLEST_ID)
manip.initialConfig.setResize(320, 320)
manip.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p)
# Linking
monoL.out.link(manip.inputImage)
monoL.frameEvent.link(script.inputs['event'])
monoL.out.link(script.inputs['frameL'])
script.outputs['floodL'].link(manipOut.input)
manip.out.link(detectionNetwork.input)
manip.out.link(objectTracker.inputTrackerFrame)
if fullFrameTracking:
manip.video.link(objectTracker.inputTrackerFrame)
else:
detectionNetwork.passthrough.link(objectTracker.inputTrackerFrame)
detectionNetwork.passthrough.link(objectTracker.inputDetectionFrame)
detectionNetwork.out.link(objectTracker.inputDetections)
objectTracker.out.link(trackerOut.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
preview = device.getOutputQueue("flood-left", 4, False)
tracklets = device.getOutputQueue("tracklets", 4, False)
startTime = time.monotonic()
counter = 0
fps = 0
frame = None
while True:
imgFrame = preview.get()
track = tracklets.get()
counter += 1
current_time = time.monotonic()
if (current_time - startTime) > 1:
fps = counter / (current_time - startTime)
counter = 0
startTime = current_time
color = (255, 0, 0)
frame = imgFrame.getCvFrame()
trackletsData = track.tracklets
for t in trackletsData:
roi = t.roi.denormalize(frame.shape[1], frame.shape[0])
x1 = int(roi.topLeft().x)
y1 = int(roi.topLeft().y)
x2 = int(roi.bottomRight().x)
y2 = int(roi.bottomRight().y)
try:
label = labelMap[t.label]
except:
label = t.label
cv2.putText(frame, str(label), (x1 + 10, y1 + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255)
cv2.putText(frame, f"ID: {[t.id]}", (x1 + 10, y1 + 35), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255)
cv2.putText(frame, t.status.name, (x1 + 10, y1 + 50), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255)
cv2.rectangle(frame, (x1, y1), (x2, y2), color, cv2.FONT_HERSHEY_SIMPLEX)
cv2.putText(frame, "NN fps: {:.2f}".format(fps), (2, frame.shape[0] - 4), cv2.FONT_HERSHEY_TRIPLEX, 0.4, color)
cv2.imshow("tracker", frame)
if cv2.waitKey(1) == ord('q'):
break
thanks,
Li