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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. cv::String folder = filePath;
  16. std::vector<cv::String> filenames;
  17. cv::glob(folder, filenames);
  18. // Random shuffle
  19. std::random_shuffle(filenames.begin(), filenames.end());
  20. Mat image = imread(filePath, 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.grab();
  38. cap.retrieve(image);
  39. return image;
  40. }
  41. void Input::freeWebcam()
  42. {
  43. this->cap.release();
  44. }