44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#include "camera.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "hikrobot/hikrobot.hpp"
|
|
#include "mindvision/mindvision.hpp"
|
|
#include "src/component/yaml.hpp"
|
|
|
|
namespace device
|
|
{
|
|
Camera::Camera(const std::string & config_path)
|
|
{
|
|
auto yaml = component::load(config_path);
|
|
auto camera_name = component::read<std::string>(yaml, "camera_name");
|
|
auto exposure_ms = component::read<double>(yaml, "exposure_ms");
|
|
|
|
if (camera_name == "mindvision") {
|
|
auto gamma = component::read<double>(yaml, "gamma");
|
|
auto vid_pid = component::read<std::string>(yaml, "vid_pid");
|
|
camera_ = std::make_unique<MindVision>(exposure_ms, gamma, vid_pid);
|
|
}
|
|
|
|
else if (camera_name == "hikrobot") {
|
|
auto gain = component::read<double>(yaml, "gain");
|
|
auto vid_pid = component::read<std::string>(yaml, "vid_pid");
|
|
camera_ = std::make_unique<HikRobot>(exposure_ms, gain, vid_pid);
|
|
}
|
|
|
|
else {
|
|
throw std::runtime_error("Unknow camera_name: " + camera_name + "!");
|
|
}
|
|
|
|
rotate_180_ = yaml["rotate_180"] ? yaml["rotate_180"].as<bool>() : false;
|
|
}
|
|
|
|
void Camera::read(cv::Mat & img, std::chrono::steady_clock::time_point & timestamp)
|
|
{
|
|
camera_->read(img, timestamp);
|
|
if (rotate_180_) {
|
|
cv::rotate(img, img, cv::ROTATE_180);
|
|
}
|
|
}
|
|
|
|
} // namespace device
|