1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "input.h"
-
- // TODO: Wenn ihr in die Zeile den Pfad zum Testvideo statt der 0 packt, benmutzt er das Testvideo.
- Input::Input(int videoHeight, int videoWidth) : cap("C:\\Line-Following-Robot\\AutonomousMode\\Test_data\\video1.h264"), videoHeight(videoHeight), videoWidth(videoWidth)
- //Input::Input(int videoHeight, int videoWidth) : cap(0), videoHeight(videoHeight), videoWidth(videoWidth)
- {
- this->cap.set(CAP_PROP_FRAME_HEIGHT, videoHeight);
- this->cap.set(CAP_PROP_FRAME_WIDTH, videoWidth);
- }
-
- Input::~Input()
- {
- this->freeWebcam();
- }
-
- Mat Input::readFile(String filePath)
- {
- std::srand(std::time(0));
- // Read all .jpg files from the specified folder
- cv::String folder = filePath;
- std::vector<cv::String> filenames;
- cv::glob(folder, filenames);
-
- // Random shuffle
- std::random_shuffle(filenames.begin(), filenames.end());
-
- Mat image = imread(filePath, IMREAD_COLOR);
-
- if(image.empty())
- {
- std::cout << "Could not read the image: " << filePath << std::endl;
- return Mat();
- //To do:Exception handeling
- }
- resize(image, image, Size(this->videoWidth, this->videoHeight));
- return image;
- }
-
- Mat Input::readWebcam()
- {
- Mat image;
-
- if(!cap.isOpened()) {
- cout << "Video capture not opened" << std::endl;
- return Mat();
- }
-
- if(!cap.grab()) {
- cout << "Could not grab frame from camera" << std::endl;
- return Mat();
- }
- cap.retrieve(image);
- return image;
- }
-
- void Input::freeWebcam()
- {
- this->cap.release();
- }
|