mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00

Added trackers factory with pre-loaded dnn models #26875 Replaces https://github.com/opencv/opencv/pull/26295 Allows to substitute custom models or initialize tracker from in-memory model. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
import os
|
|
import numpy as np
|
|
import cv2 as cv
|
|
|
|
from tests_common import NewOpenCVTests, unittest
|
|
|
|
class tracking_test(NewOpenCVTests):
|
|
|
|
def test_createMILTracker(self):
|
|
t = cv.TrackerMIL.create()
|
|
self.assertTrue(t is not None)
|
|
|
|
def test_createGoturnTracker(self):
|
|
proto = self.find_file("dnn/gsoc2016-goturn/goturn.prototxt", required=False);
|
|
weights = self.find_file("dnn/gsoc2016-goturn/goturn.caffemodel", required=False);
|
|
net = cv.dnn.readNet(proto, weights)
|
|
t = cv.TrackerGOTURN.create(net)
|
|
self.assertTrue(t is not None)
|
|
|
|
def test_createNanoTracker(self):
|
|
backbone_path = self.find_file("dnn/onnx/models/nanotrack_backbone_sim_v2.onnx", required=False);
|
|
neckhead_path = self.find_file("dnn/onnx/models/nanotrack_head_sim_v2.onnx", required=False);
|
|
backbone = cv.dnn.readNet(backbone_path)
|
|
neckhead = cv.dnn.readNet(neckhead_path)
|
|
t = cv.TrackerNano.create(backbone, neckhead)
|
|
self.assertTrue(t is not None)
|
|
|
|
def test_createVitTracker(self):
|
|
model_path = self.find_file("dnn/onnx/models/vitTracker.onnx", required=False);
|
|
model = cv.dnn.readNet(model_path)
|
|
t = cv.TrackerVit.create(model)
|
|
self.assertTrue(t is not None)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
NewOpenCVTests.bootstrap()
|