epuckCamera.hpp
Go to the documentation of this file.
1/* Copyright 2008 Renato Florentino Garcia <fgar.renato@gmail.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2, as
5 * published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16#ifndef EPUCK_CAMERA_HPP
17#define EPUCK_CAMERA_HPP
18
19#include "epuckInterface.hpp"
20#include <stdexcept>
21#include <string>
22
44{
45public:
46
47 class camera_version_error : public std::logic_error
48 {
49 public:
50 camera_version_error(int wrongVersion)
51 :logic_error(make_what(wrongVersion)){}
52 private:
53 std::string make_what(int wrongVersion);
54 };
55
56 class window_out_of_range : public std::out_of_range
57 {
58 public:
59 window_out_of_range(const std::string& whatArg)
60 :out_of_range(whatArg){}
61 };
62
63 class window_length_error : public std::length_error
64 {
65 public:
66 window_length_error(const std::string& whatArg)
67 :length_error(whatArg){}
68 window_length_error(int maxWidth, int maxHeight)
69 :length_error(make_what(maxWidth, maxHeight)){}
70 private:
71 std::string make_what(int maxWidth, int maxHeight);
72 };
73
86
104 EpuckCamera(const SerialPort* const serialPort, unsigned sensor_x1,
105 unsigned sensor_y1, unsigned sensor_width,
106 unsigned sensor_height, unsigned zoom_fact_width,
107 unsigned zoom_fact_height, ColorModes color_mode) throw();
108
109 ~EpuckCamera();
110
117 void Initialize();
118
125 std::string GetCameraVersion() const;
126
133 void GetCameraData(unsigned &imageWidth, unsigned &imageHeight,
134 EpuckCamera::ColorModes &colorMode) const;
135
141 void GetImage(unsigned char* const ptrImage);
142
143private:
144
145 static const unsigned PO3030K = 0x3030;
146 static const unsigned PO6030K = 0x6030;
147
148 unsigned sensor_x1;
149 unsigned sensor_y1;
150 unsigned sensor_width;
151 unsigned sensor_height;
152 unsigned zoom_fact_width;
153 unsigned zoom_fact_height;
154 ColorModes color_mode;
155
156 enum{
157 bpp_8,
158 bpp_16
159 }bpp;
160 unsigned imageByteSize;
161
162 unsigned imagePixelSize;
163 unsigned rowPixelLength;
164 unsigned columnPixelLength;
165
166 unsigned epuckCameraVersion;
167
168 unsigned char* tmpImage;
169 bool tmpImageAllocated;
170
171 // Check if the given camera parameters will be accepted by e-puck, and
172 // throw exceptions otherwise.
173 void checkCameraParameters() const;
174
175 // Copy the tmpImage in ptrImage, rotating 90 degrees counterclockwise.
176 template <typename T>
177 void processTmpImage(T* ptrImage) const;
178
179};
180
181#endif /* EPUCK_CAMERA_HPP */
Definition epuckCamera.hpp:48
Definition epuckCamera.hpp:64
Definition epuckCamera.hpp:57
Class for to get images from e-puck camera.
Definition epuckCamera.hpp:44
void Initialize()
Send the configurations givens in EpuckCamera constructor to e-puck.
Definition epuckCamera.cpp:135
void GetImage(unsigned char *const ptrImage)
Get a new image from e-puck.
Definition epuckCamera.cpp:203
EpuckCamera(const SerialPort *const serialPort, unsigned sensor_x1, unsigned sensor_y1, unsigned sensor_width, unsigned sensor_height, unsigned zoom_fact_width, unsigned zoom_fact_height, ColorModes color_mode)
The EpuckCamera class constructor.
Definition epuckCamera.cpp:43
ColorModes
Possible color modes for e-puck camera.
Definition epuckCamera.hpp:81
@ GREY_SCALE_MODE
Grey color mode, with 8 bits per pixel.
Definition epuckCamera.hpp:82
@ RGB_565_MODE
RGB color mode, with 16 bits per pixel.
Definition epuckCamera.hpp:83
@ YUV_MODE
YUV color mode, with 16 bits per pixel.
Definition epuckCamera.hpp:84
void GetCameraData(unsigned &imageWidth, unsigned &imageHeight, EpuckCamera::ColorModes &colorMode) const
Get the relevant configurations camera data.
Definition epuckCamera.cpp:194
std::string GetCameraVersion() const
Get the version of camera in e-puck.
Definition epuckCamera.cpp:174
Base class for all concrete interfaces of e-puck.
Definition epuckInterface.hpp:34
const SerialPort *const serialPort
A SerialPort class instance shared among the device interfaces.
Definition epuckInterface.hpp:59
Send and receive messages from e-puck.
Definition serialPort.hpp:41
Header file of the EpuckInterface class and the struct EpuckInterface::Triple.