|
1 | | -How to maximize FOV |
2 | | -=================== |
| 1 | +Maximizing FOV |
| 2 | +============== |
3 | 3 |
|
4 | | -By default, when you are using :code:`preview` output from :ref:`ColorCamera`, the DepthAI will crop the |
5 | | -frames to get the desired aspect ratio. For example, if you are using Mobilenet-SSD model, you need |
6 | | -:code:`300x300` frames. DepthAI will crop 1080P frames to :code:`1080x1080` and then resize them to :code:`300x300`. |
7 | | -This means you will lose some part of the image. |
| 4 | +In this tutorial we will look at how you can use the full FOV of the image sensor. |
8 | 5 |
|
9 | | -If you would like to maximize the FOV of the image, you can either: |
| 6 | +When you are using ``preview`` output from :ref:`ColorCamera`, DepthAI will crop the |
| 7 | +frames by default to get the desired aspect ratio. ``preview`` stream derives from ``video`` stream, which is cropped (16:9 aspect ratio, |
| 8 | +max 4k resolution) from the ``isp`` stream, which has the full FOV. |
10 | 9 |
|
11 | | -#. Change the aspect ratio (stretch the image) |
12 | | -#. Apply letterboxing to the image |
| 10 | +.. image:: /_static/images/tutorials/isp.jpg |
| 11 | + |
| 12 | +The image above is the ``isp`` output from the :ref:`ColorCamera` (12MP from IMX378). The blue rectangle represents the cropped 4K |
| 13 | +``video`` output, and the yellow rectangle represents a cropped ``preview`` output when the preview size is set to 1:1 aspect ratio |
| 14 | +(eg. when using 300x300 MobileNet-SSD NN model). |
| 15 | + |
| 16 | +In other words, you **need to use ISP output** from the :ref:`ColorCamera` **to maximize the image FOV**. A challenge |
| 17 | +occures when your NN model expects different aspect ratio (eg. 1:1) compared to isp output (eg. 4:3). Let's say we have |
| 18 | +a MobileNet-SSD which requires 300x300 frames (1:1 aspect ratio) - we have a few options: |
| 19 | + |
| 20 | +#. :ref:`Stretch the ISP frame <Change aspect ratio>` to to the 1:1 aspect ratio of the NN |
| 21 | +#. :ref:`Apply letterboxing <Letterboxing>` to the ISP frame to get 1:1 aspect ratio frame |
| 22 | +#. :ref:`Crop the ISP frame <Cropping>` to 1:1 aspect ratio and lose some FOV |
13 | 23 |
|
14 | 24 | Change aspect ratio |
15 | 25 | ******************* |
16 | 26 |
|
17 | | -Use :code:`camRgb.setPreviewKeepAspectRatio(False)`. This means the aspect ratio will not be preserved and the image |
18 | | -will be "stretched". This might be problematic for some off-the-shelf NN models, so model fine-tuning it might be required. |
19 | | -`Usage example here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-lossless-zooming/main.py#L19>`__. |
| 27 | +**Pros: Preserves full FOV. Cons: Due to stretched frames, NNs accuracy might decrease.** |
20 | 28 |
|
21 | | -.. image:: https://user-images.githubusercontent.com/18037362/144095838-d082040a-9716-4f8e-90e5-15bcb23115f9.gif |
22 | | - :target: https://youtu.be/8X0IcnkeIf8 |
| 29 | +Changing aspect ratio (**stretching**) can be used Use :code:`camRgb.setPreviewKeepAspectRatio(False)`. This means the aspect |
| 30 | +ratio will not be preserved and the image will be "stretched". This might be problematic for some off-the-shelf NN models, so some fine-tuning might be required. |
| 31 | +`Usage example here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-full-fov-nn/stretching.py>`__. |
| 32 | + |
| 33 | +.. image:: https://user-images.githubusercontent.com/18037362/180607962-e616cdc7-fcad-4bc8-a15f-617b89a2c047.jpg |
23 | 34 |
|
24 | 35 | Letterboxing |
25 | 36 | ************ |
26 | 37 |
|
27 | | -`Letterboxing <https://en.wikipedia.org/wiki/Letterboxing_%28filming%29>`__ the frames. This method will decrease |
28 | | -the size of the image and apply "black bars" above and below the image, so the aspect ratio is preserved. You can |
| 38 | +**Pros: Preserves full FOV. Cons: Smaller "frame" means less features might decrease NN accuracy.** |
| 39 | + |
| 40 | +`Letterboxing <https://en.wikipedia.org/wiki/Letterboxing_%28filming%29>`__ approach will apply "black bars" above and below |
| 41 | +the image to the full FOV (isp) frames, so the aspect ratio will be preserved. You can |
29 | 42 | achieve this by using :ref:`ImageManip` with :code:`manip.setResizeThumbnail(x,y)` (for Mobilenet :code:`x=300,y=300`). |
30 | 43 | The downside of using this method is that your actual image will be smaller, so some features might not be preserved, |
31 | 44 | which can mean the NN accuracy could decrease. |
32 | | -`Usage example here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-full-fov-nn/main.py#L28>`__. |
| 45 | +`Usage example here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-full-fov-nn/letterboxing.py>`__. |
| 46 | + |
| 47 | +.. image:: https://user-images.githubusercontent.com/18037362/180607958-0db7fb34-1221-42a1-b889-10d1f9793912.jpg |
| 48 | + |
| 49 | +Cropping |
| 50 | +******** |
| 51 | + |
| 52 | +**Pros: No NN accuracy decrease. Cons: Frame is cropped, so it's not full FOV.** |
| 53 | + |
| 54 | +Cropping the full FOV (isp) frames to match the NN aspect ratio can be used to get the best NN accuracy, but this |
| 55 | +decreases FOV. |
| 56 | +`Usage example here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-full-fov-nn/cropping.py>`__. |
33 | 57 |
|
34 | | -.. image:: /_static/images/tutorials/fov.jpeg |
| 58 | +.. image:: https://user-images.githubusercontent.com/18037362/180607873-6a476ea4-55e0-4557-a93e-a7cadcd80725.jpg |
35 | 59 |
|
| 60 | +.. include:: /includes/footer-short.rst |
0 commit comments