63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
#include <gflags/gflags.h>
|
|
#include <glog/logging.h>
|
|
#include "camera_service.h"
|
|
#include "device_manager/device_factory.h"
|
|
#include <opencv2/core/utils/filesystem.hpp>
|
|
|
|
// 定义命令行参数
|
|
DEFINE_string(address, "0.0.0.0:50051", "服务监听地址");
|
|
DEFINE_string(config, "config/camera_config.yaml", "相机配置文件路径");
|
|
DEFINE_int32(device_index, 0, "相机设备索引");
|
|
|
|
int main(int argc, char** argv) {
|
|
// 初始化glog
|
|
google::InitGoogleLogging(argv[0]);
|
|
FLAGS_logtostderr = true;
|
|
|
|
// 解析命令行参数
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
try {
|
|
// 加载相机配置
|
|
if (!cv::utils::fs::exists(FLAGS_config)) {
|
|
LOG(ERROR) << "Config file not found: " << FLAGS_config;
|
|
return 1;
|
|
}
|
|
|
|
XmlNode config;
|
|
config.load(FLAGS_config);
|
|
|
|
// 创建相机实例
|
|
auto camera = std::make_shared<cmvr::device::universalCamera>(config);
|
|
if (!camera) {
|
|
LOG(ERROR) << "Failed to create camera instance";
|
|
return 1;
|
|
}
|
|
|
|
// 创建相机服务
|
|
cmvr::device::CameraService service(camera);
|
|
|
|
// 启动服务
|
|
LOG(INFO) << "Starting camera service on " << FLAGS_address;
|
|
service.Start(FLAGS_address);
|
|
|
|
// 等待终止信号
|
|
std::string input;
|
|
std::cout << "Press 'q' to quit" << std::endl;
|
|
while (std::getline(std::cin, input)) {
|
|
if (input == "q") {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 停止服务
|
|
service.Stop();
|
|
LOG(INFO) << "Camera service stopped";
|
|
|
|
} catch (const std::exception& e) {
|
|
LOG(ERROR) << "Error: " << e.what();
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|