camera_info_manager.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 // SPDX-FileCopyrightText: Jack O'Quin
3 // SPDX-FileCopyrightText: Czech Technical University in Prague
4 
11 /*********************************************************************
12 * Software License Agreement (BSD License)
13 *
14 * Copyright (c) 2010-2012 Jack O'Quin
15 * Copyright (c) 2024 Czech Technical University in Prague
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 *
22 * * Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * * Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials provided
27 * with the distribution.
28 * * Neither the name of the author nor other contributors may be
29 * used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
40 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
42 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
44 *********************************************************************/
45 
46 #pragma once
47 
48 #include <string>
49 
52 #include <sensor_msgs/CameraInfo.h>
53 
55 {
128 class CameraInfoManager : public cras::HasLogger
129 {
130 public:
136  explicit CameraInfoManager(const std::string& cname = "camera", const std::string& url = "");
137 
144  explicit CameraInfoManager(
145  const cras::LogHelperPtr& log, const std::string& cname = "camera", const std::string& url = "");
146 
147  virtual ~CameraInfoManager();
148 
154  sensor_msgs::CameraInfo getCameraInfo();
155 
159  bool isCalibrated();
160 
169  static std::string resolveURL(const cras::LogHelperPtr& log,
170  const std::string& url, const std::string& cname, const cras::optional<double>& focalLength);
171 
177  static bool validateURL(const std::string& url);
178 
184  virtual bool setCameraName(const std::string& cname);
185 
191  virtual bool setFocalLength(double focalLength);
192 
193 protected:
195  enum class URL
196  {
197  EMPTY = 0,
198  FILE,
199  PACKAGE,
200  // URLs not supported
201  INVALID,
202  FLASH,
203  };
204 
210  static URL parseURL(const std::string& url);
211 
219  virtual bool loadCalibration(
220  const std::string& url, const std::string& cname, const cras::optional<double>& focalLength);
221 
228  virtual bool loadCalibrationFile(const std::string& filename, const std::string& cname);
229 
236  virtual bool loadCalibrationFlash(const std::string& flashURL, const std::string& cname);
237 
238 private:
244  std::string getPackageFileName(const std::string& url) const;
245 
246 protected:
247  std::string cameraName;
248  cras::optional<double> focalLength;
249  std::string url;
250  sensor_msgs::CameraInfo camInfo {};
251  bool loadedCamInfo;
252 };
253 
254 }
optional.hpp
camera_info_manager_lib::CameraInfoManager::URL::FILE
@ FILE
file:
camera_info_manager_lib::CameraInfoManager
Provides CameraInfo data for a calibrated camera. Different from camera_info_manager::CameraInfoManag...
Definition: camera_info_manager.h:161
camera_info_manager_lib::CameraInfoManager::parseURL
static URL parseURL(const std::string &url)
Parse the type of the URL.
camera_info_manager_lib::CameraInfoManager::cameraName
std::string cameraName
Camera name.
Definition: camera_info_manager.h:313
camera_info_manager_lib::CameraInfoManager::setCameraName
virtual bool setCameraName(const std::string &cname)
Set or change the name of the camera that should currently be represented by this class.
cras::HasLogger
camera_info_manager_lib::CameraInfoManager::URL
URL
recognized URL types
Definition: camera_info_manager.h:261
camera_info_manager_lib::CameraInfoManager::loadCalibration
virtual bool loadCalibration(const std::string &url, const std::string &cname, const cras::optional< double > &focalLength)
Load calibration according to camera info URL.
camera_info_manager_lib::CameraInfoManager::URL::FLASH
@ FLASH
flash:
log_utils.h
camera_info_manager_lib::CameraInfoManager::URL::EMPTY
@ EMPTY
empty string
camera_info_manager_lib::CameraInfoManager::isCalibrated
bool isCalibrated()
camera_info_manager_lib::CameraInfoManager::loadCalibrationFlash
virtual bool loadCalibrationFlash(const std::string &flashURL, const std::string &cname)
Load calibration from camera flash (not supported, but subclasses can override).
camera_info_manager_lib::CameraInfoManager::loadedCamInfo
bool loadedCamInfo
Whether camInfo load has been attempted.
Definition: camera_info_manager.h:317
camera_info_manager_lib::CameraInfoManager::setFocalLength
virtual bool setFocalLength(double focalLength)
Set or change the focal length of the camera that should currently be represented by this class.
camera_info_manager_lib::CameraInfoManager::CameraInfoManager
CameraInfoManager(const std::string &cname="camera", const std::string &url="")
Constructor. It does not load the calibration file, that is done lazily when needed.
camera_info_manager_lib::CameraInfoManager::URL::PACKAGE
@ PACKAGE
package:
camera_info_manager_lib::CameraInfoManager::resolveURL
static std::string resolveURL(const cras::LogHelperPtr &log, const std::string &url, const std::string &cname, const cras::optional< double > &focalLength)
Resolve substitution keywords in the given URL.
camera_info_manager_lib::CameraInfoManager::getCameraInfo
sensor_msgs::CameraInfo getCameraInfo()
Load and return the camera info assigned to the camera specified in constructor or by calls to setCam...
camera_info_manager_lib
Definition: camera_info_manager.h:54
camera_info_manager_lib::CameraInfoManager::~CameraInfoManager
virtual ~CameraInfoManager()
cras::LogHelperPtr
::cras::LogHelper::Ptr LogHelperPtr
camera_info_manager_lib::CameraInfoManager::URL::INVALID
@ INVALID
anything >= is invalid
camera_info_manager_lib::CameraInfoManager::loadCalibrationFile
virtual bool loadCalibrationFile(const std::string &filename, const std::string &cname)
Load calibration from the given file.
camera_info_manager_lib::CameraInfoManager::camInfo
sensor_msgs::CameraInfo camInfo
Current CameraInfo.
Definition: camera_info_manager.h:316
cras::HasLogger::log
::cras::LogHelperPtr log
camera_info_manager_lib::CameraInfoManager::url
std::string url
URL for calibration data.
Definition: camera_info_manager.h:315
camera_info_manager_lib::CameraInfoManager::validateURL
static bool validateURL(const std::string &url)
Validate a camera info URL.
camera_info_manager_lib::CameraInfoManager::getPackageFileName
std::string getPackageFileName(const std::string &url) const
Resolve the package:// part of URL with a local file.
camera_info_manager_lib::CameraInfoManager::focalLength
cras::optional< double > focalLength
Current focal length.
Definition: camera_info_manager.h:314


camera_info_manager_lib
Author(s): Martin Pecka
autogenerated on Fri Apr 4 2025 02:06:38