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.

input.cpp 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "input.h"
  2. Input::Input(/* args */) : cap(0)
  3. {
  4. const int VID_HEIGHT = 240;
  5. const int VID_WIDTH = 320;
  6. this->cap.set(CAP_PROP_FRAME_HEIGHT, VID_HEIGHT);
  7. this->cap.set(CAP_PROP_FRAME_WIDTH, VID_WIDTH);
  8. }
  9. Input::~Input()
  10. {
  11. this->freeWebcam();
  12. }
  13. Mat Input::readFile(String filePath)
  14. {
  15. std::srand(std::time(0));
  16. // Read all .jpg files from the specified folder
  17. std::string folder = filePath;
  18. std::vector<std::string> filenames;
  19. cv::glob(folder, filenames);
  20. // Random shuffle
  21. std::random_shuffle(filenames.begin(), filenames.end());
  22. Mat image = imread(filenames[0], IMREAD_COLOR);
  23. if(image.empty())
  24. {
  25. std::cout << "Could not read the image: " << filePath << std::endl;
  26. return Mat();
  27. //To do:Exception handeling
  28. }
  29. return image;
  30. }
  31. Mat Input::readWebcam()
  32. {
  33. Mat image;
  34. if(!cap.isOpened()) {
  35. cout << "Fehler";
  36. return Mat();
  37. }
  38. cap.read(image);
  39. return image;
  40. }
  41. void Input::freeWebcam()
  42. {
  43. this->cap.release();
  44. }