#include #include #include "io/usbcamera/usbcamera.hpp" #include "tasks/auto_aim/yolo.hpp" #include "tools/exiter.hpp" #include "tools/logger.hpp" #include "tools/math_tools.hpp" using namespace std::chrono_literals; const std::string keys = "{help h usage ? | | 输出命令行参数说明}" "{name n | video0 | 端口名称 }" "{@config-path | configs/sentry.yaml | 位置参数,yaml配置文件路径 }" "{d display | | 显示视频流 }"; int main(int argc, char * argv[]) { cv::CommandLineParser cli(argc, argv, keys); if (cli.has("help")) { cli.printMessage(); return 0; } tools::Exiter exiter; auto config_path = cli.get(0); auto device_name = cli.get("name"); auto display = cli.has("display"); io::USBCamera usbcam(device_name, config_path); auto_aim::YOLO yolo(config_path, true); cv::Mat img; std::chrono::steady_clock::time_point timestamp; auto last_stamp = std::chrono::steady_clock::now(); while (!exiter.exit()) { usbcam.read(img, timestamp); yolo.detect(img); auto dt = tools::delta_time(timestamp, last_stamp); last_stamp = timestamp; tools::logger()->info("{:.2f} fps", 1 / dt); std::this_thread::sleep_for(10ms); if (!display) continue; cv::imshow("img", img); if (cv::waitKey(1) == 'q') break; } }