Added the Communication Module to the repo.

This commit is contained in:
2022-11-20 20:17:30 +01:00
parent 103030c369
commit eb64c8eded
55 changed files with 225 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} ${Utils_SOURCE_DIRS})
link_directories(${Utils_SOURCE_DIRS})
add_library(Input input.cpp)
set_target_properties(Input PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(Input PRIVATE .)
target_link_libraries( Input ${OpenCV_LIBS} Utils)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
+54
View File
@@ -0,0 +1,54 @@
#include "input.h"
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
std::string folder = filePath;
std::vector<std::string> filenames;
cv::glob(folder, filenames);
// Random shuffle
std::random_shuffle(filenames.begin(), filenames.end());
Mat image = imread(filenames[0], 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 << "Fehler";
return Mat();
}
cap.read(image);
return image;
}
void Input::freeWebcam()
{
this->cap.release();
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <opencv2/opencv.hpp>
#include <opencv2/core/utils/logger.hpp>
using namespace std;
using namespace cv;
class Input
{
private:
VideoCapture cap;
public:
int videoHeight;
int videoWidth;
Input(int videoHeight, int videoWidth);
Input() = delete;
~Input();
Mat readFile(String filePath);
Mat readWebcam();
void freeWebcam();
};