Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autonomous_mode_main.cpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "lfr.h"
  2. #include <opencv2/core/utils/logger.hpp>
  3. int main(void)
  4. {
  5. //Disable opencv logging messages
  6. //cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
  7. const int thresholdBinary = 140;
  8. const int videoHeight = 720;
  9. const int videoWidth = 1280;
  10. const int gaussKernelSize = 11;
  11. std::mutex mutex;
  12. LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, [&](std::exception const &ex)
  13. {
  14. std::unique_lock<std::mutex> lock(mutex);
  15. std::cerr<<"camera exception:"<<ex.what()<<std::endl;
  16. return true;
  17. });
  18. //To calculate the frame rate
  19. std::chrono::milliseconds last = duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
  20. std::chrono::milliseconds now = duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
  21. cv::Mat img;
  22. lfr.addListener([&](LFR_Result result)
  23. {
  24. std::unique_lock<std::mutex> lock(mutex);
  25. if (!result.rawImage.empty())
  26. {
  27. cv::resize(result.rawImage, img, cv::Size(128, 64+32));
  28. //Calculate frame rate
  29. now = duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
  30. unsigned int deltaMs = (now-last).count();
  31. float delta = static_cast<float>(deltaMs) / 1000.0;
  32. float frameRate = 1.0 / static_cast<float>(delta);
  33. //std::cout << "Frame rate: " << frameRate << std::endl;
  34. last = now;
  35. }
  36. }, &mutex);
  37. lfr.startLoop();
  38. for(int finished = false; finished != 'q';){
  39. finished = std::tolower(cv::waitKey(66));
  40. std::unique_lock<std::mutex> lock(mutex);
  41. if(!img.empty()){
  42. cv::imshow("frame", img);
  43. }
  44. }
  45. }