ImageConverter.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cv_bridge/cv_bridge.h>
4 
5 #include <depthai-shared/common/CameraBoardSocket.hpp>
6 #include <depthai/depthai.hpp>
7 #include <iostream>
8 #include <opencv2/opencv.hpp>
9 #include <sstream>
10 #include <tuple>
11 #include <unordered_map>
12 
13 #ifdef IS_ROS2
14  #include "rclcpp/rclcpp.hpp"
15  #include "sensor_msgs/msg/camera_info.hpp"
16  #include "sensor_msgs/msg/image.hpp"
17  #include "std_msgs/msg/header.hpp"
18 #else
19  #include <ros/ros.h>
20 
21  #include <boost/make_shared.hpp>
22  #include <boost/range/algorithm.hpp>
23 
24  #include "sensor_msgs/CameraInfo.h"
25  #include "sensor_msgs/Image.h"
26  #include "std_msgs/Header.h"
27 
28 #endif
29 
30 namespace dai {
31 
32 namespace ros {
33 
34 #ifdef IS_ROS2
35 namespace StdMsgs = std_msgs::msg;
36 namespace ImageMsgs = sensor_msgs::msg;
37 using ImagePtr = ImageMsgs::Image::SharedPtr;
38 #else
39 namespace StdMsgs = std_msgs;
40 namespace ImageMsgs = sensor_msgs;
42 #endif
43 using TimePoint = std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration>;
44 
46  public:
47  // ImageConverter() = default;
48  ImageConverter(const std::string frameName, bool interleaved);
49  ImageConverter(bool interleaved);
50 
51  void toRosMsg(std::shared_ptr<dai::ImgFrame> inData, std::deque<ImageMsgs::Image>& outImageMsgs);
52  ImagePtr toRosMsgPtr(std::shared_ptr<dai::ImgFrame> inData);
53 
54  void toDaiMsg(const ImageMsgs::Image& inMsg, dai::ImgFrame& outData);
55 
59  cv::Mat rosMsgtoCvMat(ImageMsgs::Image& inMsg);
60 
61  ImageMsgs::CameraInfo calibrationToCameraInfo(dai::CalibrationHandler calibHandler,
62  dai::CameraBoardSocket cameraId,
63  int width = -1,
64  int height = -1,
65  Point2f topLeftPixelId = Point2f(),
66  Point2f bottomRightPixelId = Point2f());
67 
68  private:
69  static std::unordered_map<dai::RawImgFrame::Type, std::string> encodingEnumMap;
70  static std::unordered_map<dai::RawImgFrame::Type, std::string> planarEncodingEnumMap;
71 
72  // dai::RawImgFrame::Type _srcType;
74  // bool c
75  const std::string _frameName = "";
76  void planarToInterleaved(const std::vector<uint8_t>& srcData, std::vector<uint8_t>& destData, int w, int h, int numPlanes, int bpp);
77  void interleavedToPlanar(const std::vector<uint8_t>& srcData, std::vector<uint8_t>& destData, int w, int h, int numPlanes, int bpp);
78 };
79 
80 } // namespace ros
81 
82 namespace rosBridge = ros;
83 
84 } // namespace dai
static std::unordered_map< dai::RawImgFrame::Type, std::string > planarEncodingEnumMap
const std::string _frameName
ImagePtr toRosMsgPtr(std::shared_ptr< dai::ImgFrame > inData)
ImageConverter(const std::string frameName, bool interleaved)
std::chrono::time_point< std::chrono::steady_clock, std::chrono::steady_clock::duration > TimePoint
cv::Mat rosMsgtoCvMat(ImageMsgs::Image &inMsg)
void planarToInterleaved(const std::vector< uint8_t > &srcData, std::vector< uint8_t > &destData, int w, int h, int numPlanes, int bpp)
void toDaiMsg(const ImageMsgs::Image &inMsg, dai::ImgFrame &outData)
void interleavedToPlanar(const std::vector< uint8_t > &srcData, std::vector< uint8_t > &destData, int w, int h, int numPlanes, int bpp)
ImageMsgs::ImagePtr ImagePtr
static std::unordered_map< dai::RawImgFrame::Type, std::string > encodingEnumMap
ImageMsgs::CameraInfo calibrationToCameraInfo(dai::CalibrationHandler calibHandler, dai::CameraBoardSocket cameraId, int width=-1, int height=-1, Point2f topLeftPixelId=Point2f(), Point2f bottomRightPixelId=Point2f())
void toRosMsg(std::shared_ptr< dai::ImgFrame > inData, std::deque< ImageMsgs::Image > &outImageMsgs)


depthai_bridge
Author(s): Sachin Guruswamy
autogenerated on Tue May 10 2022 03:01:27