JeVois  1.17
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
CameraSensor.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2018 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
19 #include <linux/videodev2.h>
20 
21 // ####################################################################################################
22 bool jevois::sensorSupportsFormat(jevois::CameraSensor s, unsigned int fmt, unsigned int w, unsigned int h, float fps)
23 {
24  switch (s)
25  {
26  // ----------------------------------------------------------------------------------------------------
27  case jevois::CameraSensor::any:
28  return true;
29 
30  // ----------------------------------------------------------------------------------------------------
31  case jevois::CameraSensor::ov9650:
32  // This sensor supports: YUYV, BAYER, RGB565
33  // SXGA (1280 x 1024): up to 15 fps
34  // VGA ( 640 x 480): up to 30 fps
35  // CIF ( 352 x 288): up to 60 fps
36  // QVGA ( 320 x 240): up to 60 fps
37  // QCIF ( 176 x 144): up to 120 fps
38  // QQVGA ( 160 x 120): up to 60 fps
39  // QQCIF ( 88 x 72): up to 120 fps
40 
41  if (fmt != V4L2_PIX_FMT_YUYV && fmt != V4L2_PIX_FMT_SRGGB8 && fmt != V4L2_PIX_FMT_RGB565) return false;
42 
43  if (w == 1280 && h == 1024) { if (fps <= 15.0F) return true; else return false; }
44  if (w == 640 && h == 480) { if (fps <= 30.0F) return true; else return false; }
45  if (w == 352 && h == 288) { if (fps <= 60.0F) return true; else return false; }
46  if (w == 320 && h == 240) { if (fps <= 60.0F) return true; else return false; }
47  if (w == 176 && h == 144) { if (fps <= 120.0F) return true; else return false; }
48  if (w == 160 && h == 120) { if (fps <= 60.0F) return true; else return false; }
49  if (w == 88 && h == 72) { if (fps <= 120.0F) return true; else return false; }
50 
51  return false;
52 
53  // ----------------------------------------------------------------------------------------------------
54  case jevois::CameraSensor::ov2640:
55  // This sensor supports: YUYV, BAYER, RGB565
56  // UXGA (1600 x 1200): up to 15 fps
57  // SXGA (1280 x 1024): up to 15 fps
58  // 720p (1280 x 720): up to 15 fps
59  // XGA (1024 x 768): up to 15 fps
60  // SVGA ( 800 x 600): up to 40 fps
61  // VGA ( 640 x 480): up to 40 fps
62  // CIF ( 352 x 288): up to 60 fps
63  // QVGA ( 320 x 240): up to 60 fps
64  // QCIF ( 176 x 144): up to 60 fps
65  // QQVGA ( 160 x 120): up to 60 fps
66  // QQCIF ( 88 x 72): up to 60 fps
67 
68  if (fmt != V4L2_PIX_FMT_YUYV && fmt != V4L2_PIX_FMT_SRGGB8 && fmt != V4L2_PIX_FMT_RGB565) return false;
69 
70  if (w == 1600 && h == 1200) { if (fps <= 15.0F) return true; else return false; }
71  if (w == 1280 && h == 1024) { if (fps <= 15.0F) return true; else return false; }
72  if (w == 1280 && h == 720) { if (fps <= 15.0F) return true; else return false; }
73  if (w == 1024 && h == 768) { if (fps <= 15.0F) return true; else return false; }
74  if (w == 800 && h == 600) { if (fps <= 40.0F) return true; else return false; }
75  if (w == 640 && h == 480) { if (fps <= 40.0F) return true; else return false; }
76  if (w == 352 && h == 288) { if (fps <= 60.0F) return true; else return false; }
77  if (w == 320 && h == 240) { if (fps <= 60.0F) return true; else return false; }
78  if (w == 176 && h == 144) { if (fps <= 60.0F) return true; else return false; }
79  if (w == 160 && h == 120) { if (fps <= 60.0F) return true; else return false; }
80  if (w == 88 && h == 72) { if (fps <= 60.0F) return true; else return false; }
81 
82  return false;
83 
84  // ----------------------------------------------------------------------------------------------------
85  case jevois::CameraSensor::ov7725:
86  // This sensor supports: YUYV, BAYER, RGB565
87  // VGA ( 640 x 480): up to 60 fps
88  // CIF ( 352 x 288): up to 60 fps
89  // QVGA ( 320 x 240): up to 60 fps
90  // QCIF ( 176 x 144): up to 60 fps
91  // QQVGA ( 160 x 120): up to 60 fps
92  // QQCIF ( 88 x 72): up to 60 fps
93 
94  if (fmt != V4L2_PIX_FMT_YUYV && fmt != V4L2_PIX_FMT_SRGGB8 && fmt != V4L2_PIX_FMT_RGB565) return false;
95 
96  if (w == 640 && h == 480) { if (fps <= 60.0F) return true; else return false; }
97  if (w == 352 && h == 288) { if (fps <= 60.0F) return true; else return false; }
98  if (w == 320 && h == 240) { if (fps <= 60.0F) return true; else return false; }
99  if (w == 176 && h == 144) { if (fps <= 60.0F) return true; else return false; }
100  if (w == 160 && h == 120) { if (fps <= 60.0F) return true; else return false; }
101  if (w == 88 && h == 72) { if (fps <= 60.0F) return true; else return false; }
102 
103  return false;
104 
105  // ----------------------------------------------------------------------------------------------------
106  case jevois::CameraSensor::ar0135:
107  // This sensor supports: BAYER or MONO
108  // SXGA (1280 x 960): up to 54 fps
109  // 720p (1280 x 720): up to 60 fps
110  // VGA ( 640 x 480): up to 54 fps (binned version of SXGA)
111  // 360p ( 640 x 360): up to 60 fps
112  // QVGA ( 320 x 240): up to 54 fps (central crop of binned version of SXGA)
113  // 180p ( 320 x 180): up to 60 fps
114  // QQVGA ( 160 x 120): up to 54 fps (central crop of binned version of SXGA)
115  // 90p ( 160 x 90): up to 60 fps
116 
117  // We support native Bayer or Mono, and YUYV through Bayer/mono to YUYV conversion in the Camera class:
118  if (fmt != V4L2_PIX_FMT_SRGGB8 && fmt != V4L2_PIX_FMT_GREY && fmt != V4L2_PIX_FMT_YUYV) return false;
119 
120  if (w == 1280 && h == 960) { if (fps <= 54.0F) return true; else return false; }
121  if (w == 1280 && h == 720) { if (fps <= 60.0F) return true; else return false; }
122 
123  if (w == 640 && h == 480) { if (fps <= 54.0F) return true; else return false; }
124  if (w == 640 && h == 360) { if (fps <= 60.0F) return true; else return false; }
125 
126  if (w == 320 && h == 240) { if (fps <= 60.0F) return true; else return false; }
127  if (w == 320 && h == 180) { if (fps <= 60.0F) return true; else return false; }
128 
129  if (w == 160 && h == 120) { if (fps <= 60.0F) return true; else return false; }
130  if (w == 160 && h == 90) { if (fps <= 60.0F) return true; else return false; }
131 
132  return false;
133 
134  // ----------------------------------------------------------------------------------------------------
135  case jevois::CameraSensor::imx290:
136  // This sensor supports: BAYER, GREY, YUYV, RGB24, ARGB32, and more. Native size is 1920x1080 at up to
137  // 120fps. Sensor also supports 1280x720 and cropping from 1920x1080, but the A311D ISP has issues with these (frame
138  // collision as soon as capture height is not 1080). So we always capture at 1920x1080 and use the ISP to
139  // crop/rescale to any other resolution. Any size (multiple of 4) is supported through cropping & rescaling.
140 
141  /* Supported formats as reported by the Amlogic camera ISP kernel driver:
142 
143  Supported format 0 is [32-bit A/XRGB 8-8-8-8] fcc 0x34424752 [RGB4]
144  Supported format 1 is [24-bit RGB 8-8-8] fcc 0x33424752 [RGB3]
145  Supported format 2 is [Y/CbCr 4:2:0] fcc 0x3231564e [NV12]
146  Supported format 3 is [16-bit A/XYUV 4-4-4-4] fcc 0x34343459 [Y444]
147  Supported format 4 is [YUYV 4:2:2] fcc 0x56595559 [YUYV]
148  Supported format 5 is [UYVY 4:2:2] fcc 0x59565955 [UYVY]
149  Supported format 6 is [8-bit Greyscale] fcc 0x59455247 [GREY]
150  Supported format 7 is [16-bit Bayer BGBG/GRGR (Exp.)] fcc 0x32525942 [BYR2] */
151  switch (fmt)
152  {
153  // Here is what we support:
154  case V4L2_PIX_FMT_SBGGR16:
155  case V4L2_PIX_FMT_RGB32:
156  case V4L2_PIX_FMT_RGB24:
157  case V4L2_PIX_FMT_YUYV:
158  case V4L2_PIX_FMT_GREY:
159  //case V4L2_PIX_FMT_NV12: not supported yet, uses 3 planes: 12-bit (8 for Y, 8 for UV half size) Y/CbCr 4:2:0
160  //case V4L2_PIX_FMT_YUV444: not supported: 16-bit xxxxyyyy uuuuvvvv
161  //case V4L2_PIX_FMT_UYVY: not supported to avoid confusions with YUYV
162  break;
163  // Everything else is unsupported:
164  default: return false;
165  }
166 
167  // Any size up to 1080P is supported. Beware that some image processing algorithms may require image width to be a
168  // multiple of 8 or 16. Here, we do not impose this constraint as some neural nets do not have it (some even use odd
169  // input image sizes). The sensor supports up to 120fps:
170  if (w <= 1920 && h <= 1080 && fps <= 120.0) return true;
171 
172  return false;
173  }
174 
175  return false;
176 }
177 
178 // ####################################################################################################
179 bool jevois::sensorHasIMU(CameraSensor s)
180 {
181  switch (s)
182  {
183  // These sensors have an ICM20948 IMU:
184  case jevois::CameraSensor::ar0135:
185  case jevois::CameraSensor::imx290:
186  return true;
187 
188  // All other sensors do not have an IMU:
189  default:
190  return false;
191  }
192 }
F
float F
Definition: GUIhelper.C:2157
jevois::sensorHasIMU
bool sensorHasIMU(CameraSensor s)
Check whether sensor has an IMU (inertial measurement unit)
Definition: CameraSensor.C:179
jevois::sensorSupportsFormat
bool sensorSupportsFormat(CameraSensor s, unsigned int fmt, unsigned int w, unsigned int h, float fps)
Check whether a given resolution and frame rate is supported by a sensor.
CameraSensor.H
h
int h
Definition: GUIhelper.C:2157