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

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