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.

lfr.cpp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "lfr.h"
  2. LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
  3. : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler(), roi()
  4. {
  5. this->iAmLooping = false;
  6. this->thresholdBinary = thresholdBinary;
  7. this->gaussKernelSize = gaussKernelSize;
  8. this->thresholdCanny1 = thresholdCanny1;
  9. this->thresholdCanny2 = thresholdCanny2;
  10. this->apertureSizeCanny = apertureSizeCanny;
  11. this->videoFlag = false;
  12. this->saveOutputFlag = false;
  13. this->outputFileName = "";
  14. cv::Point roiOrigin(0, videoHeight*(7.5/12.0));
  15. roi = Rect(roiOrigin.x, roiOrigin.y, videoWidth, videoHeight/12);
  16. }
  17. LFR::~LFR()
  18. {
  19. if(iAmLooping)
  20. {
  21. this->endLoop();
  22. }
  23. }
  24. void LFR::loop()
  25. {
  26. if(this->videoFlag) {namedWindow("Display window");}
  27. while(iAmLooping)
  28. {
  29. Mat originalImage = input.readWebcam();
  30. Mat processedImage = originalImage;
  31. processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
  32. FrameData data = processing.calculateLineSegments(processedImage, this->roi);
  33. this->provideOutput(processedImage);
  34. }
  35. if(this->videoFlag) {destroyWindow("Display window");}
  36. input.freeWebcam();
  37. }
  38. void LFR::startLoop()
  39. {
  40. iAmLooping = true;
  41. this->loopThread=thread(&LFR::loop, this);
  42. }
  43. void LFR::endLoop()
  44. {
  45. iAmLooping = false;
  46. this->loopThread.join();
  47. return;
  48. }
  49. void LFR::provideOutput(const Mat& image)
  50. {
  51. if(this->videoFlag)
  52. {
  53. imshow("Display window", image);
  54. char c = (char)waitKey(1);
  55. }
  56. if (this->saveOutputFlag && !(this->outputFileName.empty()))
  57. {
  58. imwrite(this->outputFileName, image);
  59. }
  60. }