- Edited
Hello,
I try to run object detection and tracking on a video using a custom-trained Yolo architecture.
I've followed several tutorials I found online, but I can't make it work. I believe I miss something with the linking. I've simplified the code posted here to focus on what I believe is more important, but I can share more as needed.
I'm using the OAK - 1 POE
# Create pipeline
pipeline = dai.Pipeline()
objectTracker = pipeline.create(dai.node.ObjectTracker)
detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)
xinFrame = pipeline.create(dai.node.XLinkIn)
trackerOut = pipeline.create(dai.node.XLinkOut)
xlinkOut = pipeline.create(dai.node.XLinkOut)
nnOut = pipeline.create(dai.node.XLinkOut)
xinFrame.setStreamName("inFrame")
xlinkOut.setStreamName("trackerFrame")
trackerOut.setStreamName("tracklets")
nnOut.setStreamName("nn")
# Network specific settings
detectionNetwork.setBlobPath(nnPath)
# … other network stuff here
objectTracker.setDetectionLabelsToTrack([0]) # track only class 0
objectTracker.setTrackerType(dai.TrackerType.ZERO_TERM_COLOR_HISTOGRAM)
objectTracker.setTrackerIdAssignmentPolicy(dai.TrackerIdAssignmentPolicy.UNIQUE_ID)
objectTracker.setTrackerThreshold(0.5)
# Linking
xinFrame.out.link(objectTracker.inputTrackerFrame) # frames go to tracker object
detectionNetwork.out.link(nnOut.input) # detected info goes to output NN Q
detectionNetwork.out.link(objectTracker.inputDetections) # detected info goes to tracker object input port
detectionNetwork.passthrough.link(objectTracker.inputDetectionFrame) # (img) frames pass through the the detection node to go to tracker node
objectTracker.out.link(trackerOut.input) # tracked info goes to tracker out Q
objectTracker.passthroughTrackerFrame.link(xlinkOut.input) # frames pass through the tracker to go to xlink out Q
def isValid(x): return "None" if not x else "Valid"
with dai.Device(pipeline) as device:
print('Connected cameras: ', device.getConnectedCameras())
qIn = device.getInputQueue(name="inFrame") # Input queue for video frames
trackerFrameQ = device.getOutputQueue(name="trackerFrame", maxSize=4) # output queue for track Info ??
tracklets = device.getOutputQueue(name="tracklets", maxSize=4) # output queue for track Info ??
qDet = device.getOutputQueue(name="nn", maxSize=4) # output queue for detection info
detections = []
frame = None
video_path = "./plain_video.mp4"
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
valid, frame = cap.read() if not valid:
print("failed to read frame from video")
break
img = dai.ImgFrame()
img.setData(frame)
img.setType(dai.ImgFrame.Type.BGR888p)
img.setHeight(640)
img.setWidth(640)
trackFrame = trackerFrameQ.tryGet()
inDet = qDet.tryGet()
track = tracklets.tryGet()
if trackFrame is None or track is None or inDet is None: continue
print("got something!") # I never get to this point here!
I never get to the "got something" print. If I change the 'tryGet' to 'get' it just hangs there forever.
I assume it doesn't receive the required images to the queue, that's why it waits but I couldn't figure where my linking is wrong. I've tried so many different options. Would appreciate any help
DepthAI
#oak