How to use TrackerNano

I attempted to use TrackerNano with the latest opencv-contrib-python, I initiated the tracker just as using other dnn-based trackers:

params = cv2.TrackerNano_Params()
params.backbone = 'nanotrack_backbone.onnx' # an onnx file downloaded from the url displayed in (your doc)[]
params.neckhead = 'nanotrack_head.onnx'
tracker = cv2.TrackerNano_create(params)

frame = cv2.imread('img.png', cv2.IMREAD_GRAYSCALE) # the image is a grayscale image
cvt_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
box = cv2.selectROI("frame", cvt_frame)
tracker.init(cvt_frame, box)

Everything went fine here, but when I started tracking as below:

for frame in frames:
    flag, box = self.tracker.update(cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB))

an error came out:
(-209:Sizes of input arguments do not match) Requested and source matrices have different count of elements in function 'cv::Mat::reshape'

I’m confused what was wrong, could you please tell me the correct way to use TrackerNano?

Problem has been solved. I used the onnx file prvided in SiamTrackers/NanoTrack/models/nanotrackv2 at master · HonglinChu/SiamTrackers · GitHub
, but nanotrackerv3 rather than nanotrackv2 (since it’s said v3 could achieve better perfomance), things went good when I submissively used nanotrackerv2.

1 Like


You can check here

It is explicitly written
" * Nanotrack v2 tracker based on neural networks."