libkipr  1.0.0
camera.hpp
Go to the documentation of this file.
1 #ifndef _KIPR_CAMERA_CAMERA_HPP_
2 #define _KIPR_CAMERA_CAMERA_HPP_
3 
4 #include "kipr/color/color.hpp"
5 #include "kipr/config/config.hpp"
7 #include <cstring>
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include <memory>
12 
13 #include "kipr/camera/camera.h"
14 #include "kipr/camera/image.hpp"
15 
16 
17 // These keys are used in the config files loaded by
18 // Camera::Device
19 #define CAMERA_GROUP ("camera")
20 #define CAMERA_NUM_CHANNELS_KEY ("num_channels")
21 #define CAMERA_CHANNEL_GROUP_PREFIX ("channel_")
22 #define CAMERA_CHANNEL_TYPE_KEY ("type")
23 
24 #define CAMERA_CHANNEL_TYPE_HSV_KEY ("hsv")
25 #define CAMERA_CHANNEL_TYPE_QR_KEY ("qr")
26 #define CAMERA_CHANNEL_TYPE_ARUCO_KEY ("aruco")
27 
28 namespace cv
29 {
30  class VideoCapture;
31 }
32 
33 namespace kipr
34 {
35  namespace camera
36  {
37  class Device;
38  class Channel;
39  class DeviceImpl;
40 
41  class ConfigPath
42  {
43  public:
44  static std::string extension();
45 
46  static void setBasePath(const std::string &path);
47  static std::string path(const std::string &name = std::string());
48  static std::string defaultPath();
49  static std::string defaultConfigPath();
50  static void setDefaultConfigPath(const std::string &name);
51 
52  private:
53  static std::string s_path;
54  };
55 
56  class Device
57  {
58  public:
59  Device();
61 
62  bool open(const int number = 0, Resolution resolution = LOW_RES,
63  Model model = WHITE_2016);
64  bool isOpen() const;
65  bool close();
66  bool update();
67 
68  unsigned width() const;
69  unsigned height() const;
70 
71  static unsigned int resolutionToHeight(Resolution res);
72  static unsigned int resolutionToWidth(Resolution res);
73 
74  const std::vector<Channel *> &channels() const;
75 
76  Image rawImage() const;
77 
79  const config::Config &config() const;
80 
81  const unsigned char *bgr() const;
82 
84 
85  private:
86  void updateConfig();
87  bool initCapDevice(const unsigned width, const unsigned height);
88  int readFrame();
89  int xioctl(int fh, int request, void *arg);
90 
91  struct buffer
92  {
93  void *start;
94  size_t length;
95  };
96  struct buffer *buffers;
97  unsigned int nBuffers;
98 
99  // cv::VideoCapture *m_capture;
100  config::Config m_config;
101  std::vector<Channel *> m_channels;
102  std::unique_ptr<DeviceImpl> m_impl;
103 
104  mutable unsigned char *m_bgr;
105  mutable unsigned m_bgrSize;
106 
107  int m_fd;
108  static const char *device_name;
109  cv::VideoCapture *m_cap;
110  bool m_connected;
111 
112  Resolution m_resolution;
113  Model m_model;
114 
115  unsigned int SelectTimeoutSec;
116  unsigned int SelectTimeoutuSec;
117  };
118 
123  }
124 }
125 
126 #endif
Model
Definition: camera.h:93
@ WHITE_2016
Definition: camera.h:94
Resolution
Definition: camera.h:84
@ LOW_RES
Definition: camera.h:85
Definition: channel.hpp:15
Definition: camera.hpp:42
static void setDefaultConfigPath(const std::string &name)
static std::string defaultPath()
static std::string path(const std::string &name=std::string())
static void setBasePath(const std::string &path)
static std::string defaultConfigPath()
static std::string extension()
Definition: camera.hpp:57
Image rawImage() const
bool open(const int number=0, Resolution resolution=LOW_RES, Model model=WHITE_2016)
static unsigned int resolutionToWidth(Resolution res)
const unsigned char * bgr() const
void setConfig(const config::Config &config)
unsigned width() const
static unsigned int resolutionToHeight(Resolution res)
bool isOpen() const
const config::Config & config() const
const std::vector< Channel * > & channels() const
unsigned height() const
Definition: image.hpp:11
Definition: config.hpp:14
Definition: camera.hpp:29
Device * cDevice()
Definition: accel.hpp:7