// DaSiamRPN tracker. // Original paper: https://arxiv.org/abs/1808.06048 // Link to original repo: https://github.com/foolwood/DaSiamRPN // Links to onnx models: // - network: https://www.dropbox.com/s/rr1lk9355vzolqv/dasiamrpn_model.onnx?dl=0 // - kernel_r1: https://www.dropbox.com/s/999cqx5zrfi7w4p/dasiamrpn_kernel_r1.onnx?dl=0 // - kernel_cls1: https://www.dropbox.com/s/qvmtszx5h339a0w/dasiamrpn_kernel_cls1.onnx?dl=0 #include #include #include #include #include #include using namespace cv; using namespace cv::dnn; const char *keys = "{ help h | | Print help message }" "{ input i | | Full path to input video folder, the specific camera index. (empty for camera 0) }" "{ net | dasiamrpn_model.onnx | Path to onnx model of net}" "{ kernel_cls1 | dasiamrpn_kernel_cls1.onnx | Path to onnx model of kernel_r1 }" "{ kernel_r1 | dasiamrpn_kernel_r1.onnx | Path to onnx model of kernel_cls1 }" "{ backend | 0 | Choose one of computation backends: " "0: automatically (by default), " "1: Halide language (http://halide-lang.org/), " "2: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit), " "3: OpenCV implementation, " "4: VKCOM, " "5: CUDA }," "{ target | 0 | Choose one of target computation devices: " "0: CPU target (by default), " "1: OpenCL, " "2: OpenCL fp16 (half-float precision), " "3: VPU, " "4: Vulkan, " "6: CUDA, " "7: CUDA fp16 (half-float preprocess) }" ; 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 net = parser.get("net"); std::string kernel_cls1 = parser.get("kernel_cls1"); std::string kernel_r1 = parser.get("kernel_r1"); int backend = parser.get("backend"); int target = parser.get("target"); Ptr tracker; try { TrackerDaSiamRPN::Params params; params.model = samples::findFile(net); params.kernel_cls1 = samples::findFile(kernel_cls1); params.kernel_r1 = samples::findFile(kernel_r1); params.backend = backend; params.target = target; tracker = TrackerDaSiamRPN::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 << "siamRPN : " << net << std::endl; std::cout << "siamKernelCL1 : " << kernel_cls1 << std::endl; std::cout << "siamKernelR1 : " << kernel_r1 << std::endl; return 2; } const std::string winName = "DaSiamRPN"; 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=