Add continuous TensorRT camera inference and ready-to-run Orin package

This commit is contained in:
zmv
2026-09-23 11:28:29 +08:00
commit 71723ef3b4
53 changed files with 27755 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
#include "camera_pipeline.hpp"
#include "config.hpp"
#include "stop_signals.hpp"
#include "visualizer.hpp"
#include <functional>
#include <iostream>
#include <map>
int main(int argc,char** argv)try {
auto root=std::filesystem::canonical("/proc/self/exe").parent_path().parent_path();
auto configPath=root/"config/camera.json";
bool visualize=false;
std::map<std::string,std::function<void(int&)>> arguments{
{"--visualize",[&](int&){visualize=true;}},
{"--config",[&](int&i){if(++i>=argc)throw std::invalid_argument("--config needs a file");configPath=argv[i];}},
{"--help",[](int&){std::cout<<"camera_risk [--config FILE] [--visualize]\nContinuous camera inference; latest FrameResult stays in memory. Stop with Ctrl+C or SIGTERM.\n";std::exit(0);}}
};
for(int i=1;i<argc;++i){auto handler=arguments.find(argv[i]);if(handler==arguments.end())throw std::invalid_argument("Unknown option: "+std::string(argv[i]));handler->second(i);}
cms::CameraPipeline pipeline(cms::loadConfig(configPath));
cms::StopSignals signals(pipeline);
pipeline.start();
/*
* 下游使用示例:在下游自己的线程/调用位置读取最新结果。
* 首帧尚未完成时 result 为空;读取不会影响取图和推理。
*
* auto result = pipeline.latest();
* if (result) {
* const auto& risk = result->risk;
* const auto& people = result->persons;
* // result->frame_index / track_ids / boxes
* // result->image / door_mask_pixels / capture / timing
* // people[i].selected / smoothed / temporal:各 133 个关键点
* }
*/
// Optional observer. Closing/failing the window never requests inference stop.
if(visualize) {
try {cms::runLocalVisualization(pipeline);}
catch(std::exception const& e){std::cerr<<"Visualization unavailable; inference continues: "<<e.what()<<std::endl;}
}
pipeline.join();
return 0;
}catch(std::exception const& e){std::cerr<<"Camera pipeline failed: "<<e.what()<<std::endl;return 1;}