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 986B

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