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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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()
  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. }
  15. LFR::~LFR()
  16. {
  17. if(iAmLooping)
  18. {
  19. this->endLoop();
  20. }
  21. }
  22. void LFR::loop()
  23. {
  24. if(this->videoFlag) {namedWindow("Display window");}
  25. while(iAmLooping)
  26. {
  27. Mat image = input.readWebcam();
  28. processing.processImage(image, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
  29. std::vector<Vec4i> lines = processing.calculateLineSegments(image);
  30. for( size_t i = 0; i < lines.size(); i++ )
  31. {
  32. line( image, Point(lines[i][0], lines[i][1]),
  33. Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
  34. }
  35. if(this->videoFlag)
  36. {
  37. imshow("Display window", image);
  38. char c = (char)waitKey(1);
  39. }
  40. if (this->saveOutputFlag && !(this->outputFileName.empty()))
  41. {
  42. imwrite(this->outputFileName, image);
  43. }
  44. }
  45. if(this->videoFlag) {destroyWindow("Display window");}
  46. input.freeWebcam();
  47. }
  48. void LFR::startLoop()
  49. {
  50. iAmLooping = true;
  51. this->loopThread=thread(&LFR::loop, this);
  52. }
  53. void LFR::endLoop()
  54. {
  55. iAmLooping = false;
  56. this->loopThread.join();
  57. return;
  58. }