Create camera class
This commit is contained in:
parent
0690c7b5c9
commit
ac7ea31705
@ -24,8 +24,12 @@ endif()
|
|||||||
# install(DIRECTORY data/ DESTINATION share/text_reader/data)
|
# install(DIRECTORY data/ DESTINATION share/text_reader/data)
|
||||||
|
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/camera_manager.hpp)
|
||||||
|
|
||||||
# Create the executable
|
# Create the executable
|
||||||
add_executable(text_reader src/main.cpp)
|
add_executable(text_reader src/main.cpp
|
||||||
|
src/camera_manager.cpp
|
||||||
|
)
|
||||||
|
|
||||||
# Copy data files to build directory
|
# Copy data files to build directory
|
||||||
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
|
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
|
||||||
|
|||||||
11
src/camera_manager.cpp
Normal file
11
src/camera_manager.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "camera_manager.hpp"
|
||||||
|
|
||||||
|
CameraManager::CameraManager() { ; }
|
||||||
|
|
||||||
|
void CameraManager::add_rtsp_camera(const std::string& rtsp_address,
|
||||||
|
int camera_Id) {
|
||||||
|
RtspCameraConfig current_camera;
|
||||||
|
current_camera.address = rtsp_address;
|
||||||
|
current_camera.camera_id = camera_Id;
|
||||||
|
camera_list.push_back(current_camera);
|
||||||
|
}
|
||||||
16
src/camera_manager.hpp
Normal file
16
src/camera_manager.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct RtspCameraConfig {
|
||||||
|
int camera_id;
|
||||||
|
std::string address;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CameraManager {
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
std::vector<RtspCameraConfig> camera_list;
|
||||||
|
CameraManager();
|
||||||
|
void add_rtsp_camera(const std::string&, int);
|
||||||
|
};
|
||||||
24
src/main.cpp
24
src/main.cpp
@ -1,19 +1,23 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "camera_manager.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
int main() {
|
int load_rtsp_address() {
|
||||||
// Path handling works across platforms
|
// Path handling works across platforms
|
||||||
fs::path data_dir = "/home/user2/temp_code/text_reader/data";
|
fs::path data_dir = "/home/user2/temp_code/text_reader/data";
|
||||||
fs::path file_path = data_dir / "example.txt";
|
fs::path file_path = data_dir / "example.txt";
|
||||||
|
CameraManager* camera_manager = new CameraManager();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
throw std::runtime_error("Failed to open file: " + file_path.string());
|
throw std::runtime_error("Failed to open file: " +
|
||||||
|
file_path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Contents of '" << file_path << "':\n";
|
std::cout << "Contents of '" << file_path << "':\n";
|
||||||
@ -23,12 +27,14 @@ int main() {
|
|||||||
int line_number = 1;
|
int line_number = 1;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
std::cout << "Line " << line_number++ << ": " << line << '\n';
|
std::cout << "Line " << line_number++ << ": " << line << '\n';
|
||||||
|
camera_manager->add_rtsp_camera(line, line_number);
|
||||||
}
|
}
|
||||||
}
|
} catch (const std::exception& e) {
|
||||||
catch (const std::exception& e) {
|
|
||||||
std::cerr << "Error: " << e.what() << '\n';
|
std::cerr << "Error: " << e.what() << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main() { load_rtsp_address(); }
|
||||||
Loading…
x
Reference in New Issue
Block a user