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

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. resize(image, image, Size(this->videoWidth, this->videoHeight));
  28. return image;
  29. }
  30. Mat Input::readWebcam()
  31. {
  32. Mat image;
  33. if(!cap.isOpened()) {
  34. cout << "Fehler";
  35. return Mat();
  36. }
  37. cap.read(image);
  38. return image;
  39. }
  40. void Input::freeWebcam()
  41. {
  42. this->cap.release();
  43. }