4 #include <linux/videodev2.h> 19 else if (str ==
"read")
21 else if (str ==
"userptr")
29 if ((str ==
"yuyv") || (str ==
"yuv"))
31 else if (str ==
"uyvy")
33 else if (str ==
"mjpeg")
35 else if (str ==
"h264")
37 else if (str ==
"yuvmono10")
39 else if (str ==
"rgb24")
41 else if (str ==
"grey")
43 else if (str ==
"yu12")
45 else if (str ==
"bgr24")
83 else if (str ==
"yuv422p")
96 return V4L2_PIX_FMT_YUYV;
98 return V4L2_PIX_FMT_UYVY;
100 return V4L2_PIX_FMT_MJPEG;
102 return V4L2_PIX_FMT_H264;
105 return V4L2_PIX_FMT_YUYV;
107 return V4L2_PIX_FMT_RGB24;
109 return V4L2_PIX_FMT_BGR24;
112 return V4L2_PIX_FMT_GREY;
114 return V4L2_PIX_FMT_YUV420;
121 const unsigned char &u,
122 const unsigned char &v,
127 const int y2 =
static_cast<int>(y);
128 const int u2 =
static_cast<int>(u - 128);
129 const int v2 =
static_cast<int>(v - 128);
138 int r2 = y2 + ((v2 * 37221) >> 15);
139 int g2 = y2 - (((u2 * 12975) + (v2 * 18949)) >> 15);
140 int b2 = y2 + ((u2 * 66883) >> 15);
154 for (i = 0, j = 0; i < (NumPixels << 1); i += 2, j += 1)
157 MONO[j] = (
unsigned char)(((RAW[i + 0] >> 2) & 0x3F) | ((RAW[i + 1] << 6) & 0xC0));
162 bool YUYV2RGB(
const char *YUV,
char *&RGB,
const int &NumPixels)
165 unsigned char y0, y1, u, v;
166 unsigned char r, g, b;
168 for (i = 0, j = 0; i < (NumPixels << 1); i += 4, j += 6)
170 y0 = (
unsigned char)YUV[i + 0];
171 u = (
unsigned char)YUV[i + 1];
172 y1 = (
unsigned char)YUV[i + 2];
173 v = (
unsigned char)YUV[i + 3];
186 bool COPY2RGB(
const char *input,
char *&output,
const int &NumPixels)
188 memcpy(output, input, NumPixels * 3);
192 bool YUV4202RGB(
char *YUV,
char *&RGB,
const int &width,
const int &height)
194 cv::Size size(height, width);
195 cv::Mat cv_img(height * 1.5, width, CV_8UC1, YUV);
196 cv::Mat cv_out(height, width, CV_8UC3, RGB);
197 cvtColor(cv_img, cv_out, cv::COLOR_YUV420p2BGR);
201 std::string
FCC2S(
const unsigned int &val)
206 s += (val >> 8) & 0x7f;
207 s += (val >> 16) & 0x7f;
208 s += (val >> 24) & 0x7f;
209 if (val & (1 << 31)) {
215 bool UYVY2RGB(
const char *YUV,
char *&RGB,
const int &NumPixels)
218 unsigned char y0, y1, u, v;
219 unsigned char r, g, b;
220 for (i = 0, j = 0; i < (NumPixels << 1); i += 4, j += 6) {
221 u = (
unsigned char)YUV[i + 0];
222 y0 = (
unsigned char)YUV[i + 1];
223 v = (
unsigned char)YUV[i + 2];
224 y1 = (
unsigned char)YUV[i + 3];
240 int add_underscore = 0;
243 if (isalnum(*name)) {
247 s += std::string(1, tolower(*name));
249 else if (s.length()) add_underscore = 1;
unsigned char CLIPVALUE(const int &val)
bool YUV4202RGB(char *YUV, char *&RGB, const int &width, const int &height)
color_format_t color_format_from_string(const std::string &str)
std::string FCC2S(const unsigned int &val)
bool MONO102MONO8(const char *RAW, char *&MONO, const int &NumPixels)
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
std::string pixel_format_to_string(const uint32_t &pixelformat)
io_method_t io_method_from_string(const std::string &str)
std::string v4l_control_name_to_param_name(const char *name)
bool UYVY2RGB(const char *YUV, char *&RGB, const int &NumPixels)
pixel_format_t pixel_format_from_string(const std::string &str)
bool COPY2RGB(const char *input, char *&output, const int &NumPixels)
bool YUYV2RGB(const char *YUV, char *&RGB, const int &NumPixels)
unsigned int v4l_pixel_format_from_pixel_format(const pixel_format_t &pixelformat, bool &mono)
bool YUV2RGB(const unsigned char &y, const unsigned char &u, const unsigned char &v, unsigned char *r, unsigned char *g, unsigned char *b)