// NanoTrack // Link to original inference code: https://github.com/HonglinChu/NanoTrack // Link to original training repo: https://github.com/HonglinChu/SiamTrackers/tree/master/NanoTrack // backBone model: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/onnx/nanotrack_backbone_sim.onnx // headNeck model: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/onnx/nanotrack_head_sim.onnx #include #include #include #include #include #include using namespace cv; using namespace cv::dnn; std::string param_keys = "{ help h | | Print help message }" "{ input i | | Full path to input video folder, the specific camera index. (empty for camera 0) }" "{ backbone | backbone.onnx | Path to onnx model of backbone.onnx}" "{ headneck | headneck.onnx | Path to onnx model of headneck.onnx }"; std::string backend_keys = cv::format( "{ backend | 0 | Choose one of computation backends: " "%d: automatically (by default), " "%d: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit), " "%d: OpenCV implementation, " "%d: VKCOM, " "%d: CUDA }", cv::dnn::DNN_BACKEND_DEFAULT, cv::dnn::DNN_BACKEND_INFERENCE_ENGINE, cv::dnn::DNN_BACKEND_OPENCV, cv::dnn::DNN_BACKEND_VKCOM, cv::dnn::DNN_BACKEND_CUDA); std::string target_keys = cv::format( "{ target | 0 | 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) }", 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); std::string keys = param_keys + backend_keys + target_keys; static int run(int argc, char** argv) { // Parse command line arguments. CommandLineParser parser(argc, argv, keys); if (parser.has("help")) { parser.printMessage(); return 0; } std::string inputName = parser.get("input"); std::string backbone = parser.get("backbone"); std::string headneck = parser.get("headneck"); int backend = parser.get("backend"); int target = parser.get("target"); Ptr tracker; try { TrackerNano::Params params; params.backbone = samples::findFile(backbone); params.neckhead = samples::findFile(headneck); params.backend = backend; params.target = target; tracker = TrackerNano::create(params); } catch (const cv::Exception& ee) { std::cerr << "Exception: " << ee.what() << std::endl; std::cout << "Can't load the network by using the following files:" << std::endl; std::cout << "backbone : " << backbone << std::endl; std::cout << "headneck : " << headneck << std::endl; return 2; } const std::string winName = "NanoTrack"; namedWindow(winName, WINDOW_AUTOSIZE); // Open a video file or an image file or a camera stream. VideoCapture cap; if (inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1)) { int c = inputName.empty() ? 0 : inputName[0] - '0'; std::cout << "Trying to open camera #" << c << " ..." << std::endl; if (!cap.open(c)) { std::cout << "Capture from camera #" << c << " didn't work. Specify -i=