Home | History | Annotate | Download | only in CameraITS
      1 # Copyright 2013 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 
     16 Android Camera Imaging Test Suite (ITS)
     17 =======================================
     18 
     19 1. Introduction
     20 ---------------
     21 
     22 The ITS is a framework for running tests on the images produced by an Android
     23 camera. The general goal of each test is to configure the camera in a desired
     24 manner and capture one or more shots, and then examine the shots to see if
     25 they contain the expected image data. Many of the tests will require that the
     26 camera is pointed at a specific target chart or be illuminated at a specific
     27 intensity.
     28 
     29 2. Setup
     30 --------
     31 
     32 There are two components to the ITS:
     33 1. The Android device running ItsService.apk.
     34 2. A host machine connected to the Android device that runs Python tests.
     35 
     36 2.1. Device setup
     37 -----------------
     38 
     39 Build and install ItsService.apk for your device. After setting up your
     40 shell for Android builds, from the pdk/apps/CameraITS directory run the
     41 following commands:
     42 
     43     cd service
     44     mm
     45     adb install -r <YOUR_OUTPUT_PATH>/ItsService.apk
     46 
     47 using whatever path is appropriate to your output ItsService.apk file.
     48 
     49 2.2. Host PC setup
     50 ------------------
     51 
     52 The first pre-requisite is the Android SDK, as adb is used to communicate with
     53 the device.
     54 
     55 The test framework is based on Python on the host machine. It requires
     56 Python 2.7 and the scipy/numpy stack, including the Python Imaging Library.
     57 
     58 (For Ubuntu users)
     59 
     60     sudo apt-get install python-numpy python-scipy python-matplotlib
     61 
     62 (For other users)
     63 
     64 All of these pieces can be installed on your host machine separately,
     65 however it is highly recommended to install a bundled distribution of
     66 Python that comes with these modules. Some different bundles are listed
     67 here:
     68 
     69     http://www.scipy.org/install.html
     70 
     71 Of these, Anaconda has been verified to work with these scripts, and it is
     72 available on Mac, Linux, and Windows from here:
     73 
     74     http://continuum.io/downloads
     75 
     76 Note that the Anaconda python executable's directory must be at the front of
     77 your PATH environment variable, assuming that you are using this Python
     78 distribution. The Anaconda installer may set this up for you automatically.
     79 
     80 Once your Python installation is ready, set up the test environment.
     81 
     82 2.2.1. Linux + Mac OS X
     83 -----------------------
     84 
     85 On Linux or Mac OS X, run the following command (in a terminal) from the
     86 pdk/apps/CameraITS directory, from a bash shell:
     87 
     88     source build/envsetup.sh
     89 
     90 This will do some basic sanity checks on your Python installation, and set up
     91 the PYTHONPATH environment variable.
     92 
     93 2.2.2. Windows
     94 --------------
     95 
     96 On Windows, the bash script won't run (unless you have cygwin (which has not
     97 been tested)), but all you need to do is set your PYTHONPATH environment
     98 variable in your shell to point to the pdk/apps/CameraITS/pymodules directory,
     99 giving an absolute path. Without this, you'll get "import" errors when running
    100 the test scripts.
    101 
    102 3. Python framework overview
    103 ----------------------------
    104 
    105 The Python modules are under the pymodules directory, in the "its" package.
    106 
    107 * its.device: encapsulates communication with ItsService.apk service running
    108   on the device
    109 * its.objects: contains a collection of functions for creating Python objects
    110   corresponding to the Java objects which ItsService.apk uses
    111 * its.image: contains a collection of functions (built on numpy arrays) for
    112   processing captured images
    113 * its.error: the exception/error class used in this framework
    114 
    115 All of these module have associated unit tests; to run the unit tests, execute
    116 the modules (rather than importing them).
    117 
    118 3.1. Device control
    119 -------------------
    120 
    121 The its.device.ItsSession class encapsulates a session with a connected device
    122 under test (which is running ItsService.apk).
    123 
    124 As an overview, the ItsSession.do_capture() function takes a Python dictionary
    125 object as an argument, converts that object to JSON, and sends it to the
    126 device over adb which then deserializes from the JSON object representation to
    127 Camera2 Java objects (CaptureRequests) which are used to specify one or more
    128 captures. Once the captures are complete, the resultant images are copied back
    129 to the host machine (using adb pull), along with JSON representations of the
    130 CaptureResult and other objects that describe the shot that was actually taken.
    131 
    132 The Python dictionary object that is used to specify what shots to capture and
    133 that is passed as an argument to the do_capture() function can have the
    134 following top-level keys:
    135 
    136     captureRequest
    137     captureRequestList
    138     outputSurface
    139 
    140 Exactly one of captureRequest and captureRequestList must be present, and
    141 outputSurface is optional. Look at the tests directory for examples of
    142 specifying these objects.
    143 
    144 The captureRequest object can contain key/value entries corresponding to any
    145 of the Java CaptureRequest object fields. The captureRequestList object is
    146 a list of such objecs, corresponding to a burst capture specification.
    147 
    148 The outputSurface object is used to specify the width, height, and format of
    149 the output images that are captured. Currently supported formats are "jpg" and
    150 "yuv", where "yuv" is YUV420 fully planar. The default output surface is a
    151 full sensor YUV420 frame.
    152 
    153 The metadata that is returned along with the captured images is also in JSON
    154 format, serialized from the CaptureRequest and CaptureResult objects that were
    155 passed to the capture listener, as well as the CameraProperties object.
    156 
    157 3.2. Image processing and analysis
    158 ----------------------------------
    159 
    160 The its.image module is a collection of Python functions, built on top of numpy
    161 arrays, for manipulating captured images. Some functions of note include:
    162 
    163     load_yuv420_to_rgb_image
    164     apply_lut_to_image
    165     apply_matrix_to_image
    166     write_image
    167 
    168 The scripts in the tests directory make use of these modules.
    169 
    170 Note that it's important to do heavy image processing using the efficient numpy
    171 ndarray operations, rather than writing complex loops in standard Python to
    172 process pixels. Refer to online docs and examples of numpy for information on
    173 this.
    174 
    175 3.3. Tests
    176 ----------
    177 
    178 The tests directory contains a number of self-contained test scripts. All
    179 tests should pass if the tree is in a good state.
    180 
    181 Most of the tests save various files in the current directory. To have all the
    182 output files put into a separate directory, run the script from that directory,
    183 for example:
    184 
    185     mkdir out
    186     cd out
    187     python ../tests/test_linearity.py
    188 
    189 Any test can be specified to reboot the camera prior to capturing any shots, by
    190 adding a "reboot" or "reboot=N" command line argument, where N is the number of
    191 seconds to wait after rebooting the device before sending any commands; the
    192 default is 30 seconds.
    193 
    194     python tests/test_linearity.py reboot
    195     python tests/test_linearity.py reboot=20
    196 
    197 3.4. Docs
    198 ---------
    199 
    200 The pydoc tool can generate HTML docs for the ITS Python modules, using the
    201 following command (run after PYTHONPATH has been set up as described above):
    202 
    203     pydoc -w its its.device its.image its.error its.objects
    204 
    205 4. Known issues
    206 ---------------
    207 
    208 The Python test scripts don't work if multiple devices are connected to the
    209 host machine; currently, the its.device module uses a simplistic "adb -d"
    210 approach to communicating with the device, assuming that there is only one
    211 device connected. Fixing this is a TODO.
    212 
    213