main.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #include "FeedLevelDetector.h"
  2. #include <iostream>
  3. int main(int argc, char** argv) {
  4. FeedLevelDetector detector;
  5. // 解析命令行参数
  6. if (argc == 2) {
  7. // 单张图片模式
  8. detector.detectFeedLevel(argv[1]);
  9. FeedLevelDetector detector;
  10. float distance = detector.detectFeedLevel(argv[1]);
  11. std::cout << "Feed level distance from top: " << distance << " pixels" << std::endl;
  12. cv::waitKey(0);
  13. } else if (argc == 3 && std::string(argv[1]) == "--camera") {
  14. // 摄像头模式,设置采集频率
  15. int interval = std::stoi(argv[2]);
  16. detector.setCaptureInterval(interval);
  17. detector.startDetectionFromCamera();
  18. } else {
  19. std::cerr << "Usage:" << std::endl;
  20. std::cerr << " 1. Image mode: " << argv[0] << " <image_path>" << std::endl;
  21. std::cerr << " 2. Camera mode: " << argv[0] << " --camera <interval_sec>" << std::endl;
  22. std::cerr << " (interval_sec: 10, 30, or 60)" << std::endl;
  23. return -1;
  24. }
  25. return 0;
  26. }