Merge pull request #26153 from onurcankaraman:sample/trackerUpdate

sample: tracker parameters updated
pull/25569/head
Alexander Smorkalov 2 months ago committed by GitHub
commit ee685017c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 34
      samples/python/tracker.py

@ -24,6 +24,10 @@ USAGE:
[--nanotrack_backbone NANOTRACK_BACKBONE] [--nanotrack_backbone NANOTRACK_BACKBONE]
[--nanotrack_headneck NANOTRACK_TARGET] [--nanotrack_headneck NANOTRACK_TARGET]
[--vittrack_net VITTRACK_MODEL] [--vittrack_net VITTRACK_MODEL]
[--vittrack_net VITTRACK_MODEL]
[--tracking_score_threshold TRACKING SCORE THRESHOLD FOR ONLY VITTRACK]
[--backend CHOOSE ONE OF COMPUTATION BACKEND]
[--target CHOOSE ONE OF COMPUTATION TARGET]
''' '''
# Python 2/3 compatibility # Python 2/3 compatibility
@ -37,6 +41,11 @@ import argparse
from video import create_capture, presets from video import create_capture, presets
backends = (cv.dnn.DNN_BACKEND_DEFAULT, cv.dnn.DNN_BACKEND_HALIDE, cv.dnn.DNN_BACKEND_INFERENCE_ENGINE, cv.dnn.DNN_BACKEND_OPENCV,
cv.dnn.DNN_BACKEND_VKCOM, cv.dnn.DNN_BACKEND_CUDA)
targets = (cv.dnn.DNN_TARGET_CPU, cv.dnn.DNN_TARGET_OPENCL, cv.dnn.DNN_TARGET_OPENCL_FP16, cv.dnn.DNN_TARGET_MYRIAD,
cv.dnn.DNN_TARGET_VULKAN, cv.dnn.DNN_TARGET_CUDA, cv.dnn.DNN_TARGET_CUDA_FP16)
class App(object): class App(object):
def __init__(self, args): def __init__(self, args):
@ -57,15 +66,22 @@ class App(object):
params.model = self.args.dasiamrpn_net params.model = self.args.dasiamrpn_net
params.kernel_cls1 = self.args.dasiamrpn_kernel_cls1 params.kernel_cls1 = self.args.dasiamrpn_kernel_cls1
params.kernel_r1 = self.args.dasiamrpn_kernel_r1 params.kernel_r1 = self.args.dasiamrpn_kernel_r1
params.backend = args.backend
params.target = args.target
tracker = cv.TrackerDaSiamRPN_create(params) tracker = cv.TrackerDaSiamRPN_create(params)
elif self.trackerAlgorithm == 'nanotrack': elif self.trackerAlgorithm == 'nanotrack':
params = cv.TrackerNano_Params() params = cv.TrackerNano_Params()
params.backbone = args.nanotrack_backbone params.backbone = args.nanotrack_backbone
params.neckhead = args.nanotrack_headneck params.neckhead = args.nanotrack_headneck
params.backend = args.backend
params.target = args.target
tracker = cv.TrackerNano_create(params) tracker = cv.TrackerNano_create(params)
elif self.trackerAlgorithm == 'vittrack': elif self.trackerAlgorithm == 'vittrack':
params = cv.TrackerVit_Params() params = cv.TrackerVit_Params()
params.net = args.vittrack_net params.net = args.vittrack_net
params.tracking_score_threshold = args.tracking_score_threshold
params.backend = args.backend
params.target = args.target
tracker = cv.TrackerVit_create(params) tracker = cv.TrackerVit_create(params)
else: else:
sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn, nanotrack.".format(self.trackerAlgorithm)) sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn, nanotrack.".format(self.trackerAlgorithm))
@ -141,6 +157,24 @@ if __name__ == '__main__':
parser.add_argument("--nanotrack_backbone", type=str, default="nanotrack_backbone_sim.onnx", help="Path to onnx model of NanoTrack backBone") parser.add_argument("--nanotrack_backbone", type=str, default="nanotrack_backbone_sim.onnx", help="Path to onnx model of NanoTrack backBone")
parser.add_argument("--nanotrack_headneck", type=str, default="nanotrack_head_sim.onnx", help="Path to onnx model of NanoTrack headNeck") parser.add_argument("--nanotrack_headneck", type=str, default="nanotrack_head_sim.onnx", help="Path to onnx model of NanoTrack headNeck")
parser.add_argument("--vittrack_net", type=str, default="vitTracker.onnx", help="Path to onnx model of vittrack") parser.add_argument("--vittrack_net", type=str, default="vitTracker.onnx", help="Path to onnx model of vittrack")
parser.add_argument('--tracking_score_threshold', type=float, help="Tracking score threshold. If a bbox of score >= 0.3, it is considered as found ")
parser.add_argument('--backend', choices=backends, default=cv.dnn.DNN_BACKEND_DEFAULT, type=int,
help="Choose one of computation backends: "
"%d: automatically (by default), "
"%d: Halide language (http://halide-lang.org/), "
"%d: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit), "
"%d: OpenCV implementation, "
"%d: VKCOM, "
"%d: CUDA"% backends)
parser.add_argument("--target", choices=targets, default=cv.dnn.DNN_TARGET_CPU, type=int,
help="Choose one of target computation devices: "
'%d: CPU target (by default), '
'%d: OpenCL, '
'%d: OpenCL fp16 (half-float precision), '
'%d: VPU, '
'%d: VULKAN, '
'%d: CUDA, '
'%d: CUDA fp16 (half-float preprocess)'% targets)
args = parser.parse_args() args = parser.parse_args()
App(args).run() App(args).run()

Loading…
Cancel
Save