# How to use TrackerNano

**URL:** <https://forum.opencv.org/t/how-to-use-trackernano/12251>\
**Category:** Python\
**Tags:** dnn, tracking\
**Created:** [March 6, 2023, 8:28am UTC](https://forum.opencv.org/t/how-to-use-trackernano/12251 "2023-03-06T08:28:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiaojing\_Zhu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xiaojing_zhu/32/7310_2.png) [@Xiaojing\_Zhu](https://forum.opencv.org/u/Xiaojing_Zhu)\
**Post date:** [March 6, 2023, 8:28am UTC](https://forum.opencv.org/t/how-to-use-trackernano/12251/1 "2023-03-06T08:28:07Z")

</div>

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

```python
params = cv2.TrackerNano_Params()
params.backbone = 'nanotrack_backbone.onnx' # an onnx file downloaded from the url displayed in (your doc)[https://docs.opencv.org/4.7.0/d8/d69/classcv_1_1TrackerNano.html]
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:

```python
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`?

---

<div class="post-metadata">

**Author:** ![Xiaojing\_Zhu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xiaojing_zhu/32/7310_2.png) [@Xiaojing\_Zhu](https://forum.opencv.org/u/Xiaojing_Zhu)\
**Post date:** [March 6, 2023, 8:54am UTC](https://forum.opencv.org/t/how-to-use-trackernano/12251/2 "2023-03-06T08:54:13Z")

</div>

Problem has been solved. I used the onnx file prvided in [SiamTrackers/NanoTrack/models/nanotrackv2 at master · HonglinChu/SiamTrackers · GitHub](https://github.com/HonglinChu/SiamTrackers/tree/master/NanoTrack/models/nanotrackv2)  
, but nanotracker **v3** rather than nanotrack **v2** (since it’s said v3 could achieve better perfomance), things went good when I submissively used nanotrackerv2.

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [October 10, 2023, 8:31am UTC](https://forum.opencv.org/t/how-to-use-trackernano/12251/3 "2023-10-10T08:31:59Z")

</div>

Hello

You can check [here](https://github.com/opencv/opencv/wiki/ChangeLog)

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