Autoware.Auto
camera_wrapper.hpp
Go to the documentation of this file.
1 // Copyright 2020 Apex.AI, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SPINNAKER_CAMERA_DRIVER__CAMERA_WRAPPER_HPP_
16 #define SPINNAKER_CAMERA_DRIVER__CAMERA_WRAPPER_HPP_
17 
18 #ifndef DOXYGEN_SKIP
19 #include <Spinnaker.h>
20 #endif
21 
24 #include <sensor_msgs/msg/image.hpp>
25 
26 #include <memory>
27 #include <string>
28 #include <functional>
29 
30 namespace autoware
31 {
32 namespace drivers
33 {
34 namespace camera
35 {
36 namespace spinnaker
37 {
38 
43 class SPINNAKER_CAMERA_PUBLIC CameraWrapper : public Spinnaker::ImageEventHandler
44 {
45 public:
47  using ImageCallbackFunction = std::function<void (
48  std::uint32_t,
49  std::unique_ptr<sensor_msgs::msg::Image>)>;
50 
52  explicit CameraWrapper(
53  std::uint32_t camera_index,
54  const Spinnaker::CameraPtr & camera,
55  const CameraSettings & camera_settings);
56 
58  explicit CameraWrapper(
59  std::uint32_t camera_index,
60  const Spinnaker::CameraPtr & camera);
61 
63  ~CameraWrapper() override;
64 
65  // We don't expect this class to be coppied over, so forbid copying.
66  CameraWrapper(const CameraWrapper &) = delete;
67  CameraWrapper & operator=(const CameraWrapper &) = delete;
68 
69  // It is still ok to move this camera.
70  CameraWrapper(CameraWrapper &&) = default;
71  CameraWrapper & operator=(CameraWrapper &&) = default;
72 
75  void OnImageEvent(Spinnaker::ImagePtr image) override;
76 
78  void configure_camera(const CameraSettings & camera_settings);
79 
81  std::unique_ptr<sensor_msgs::msg::Image> retreive_image() const;
82 
84  void start_capturing();
85 
87  void stop_capturing();
88 
90  void set_on_image_callback(ImageCallbackFunction callback);
91 
92 private:
94  static std::unique_ptr<sensor_msgs::msg::Image> convert_to_image_msg(
95  const Spinnaker::ImagePtr & image, const std::string & frame_id);
96 
98  static Spinnaker::PixelFormatEnums convert_to_pixel_format_enum(const std::string & pixel_format);
100  static std::string convert_to_pixel_format_string(Spinnaker::PixelFormatEnums pixel_format);
101 
103  std::uint32_t m_camera_index{};
105  Spinnaker::CameraPtr m_camera{};
107  std::string m_frame_id{};
109  bool m_is_camera_configured{};
111  bool m_camera_is_capturing{};
112 
114  ImageCallbackFunction m_on_image_callback{};
115 };
116 
117 } // namespace spinnaker
118 } // namespace camera
119 } // namespace drivers
120 } // namespace autoware
121 
122 #endif // SPINNAKER_CAMERA_DRIVER__CAMERA_WRAPPER_HPP_
autoware::drivers::camera::spinnaker::CameraWrapper
Definition: camera_wrapper.hpp:43
autoware::drivers::camera::spinnaker::CameraSettings
Encapsulate settings that make sense to pass to a camera.
Definition: camera_settings.hpp:35
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
visibility_control.hpp
autoware::drivers::camera::spinnaker::CameraWrapper::ImageCallbackFunction
std::function< void(std::uint32_t, std::unique_ptr< sensor_msgs::msg::Image >)> ImageCallbackFunction
A typedef for the callback function used to return an image message to the user.
Definition: camera_wrapper.hpp:49
camera_settings.hpp