aboutsummaryrefslogtreecommitdiff
path: root/apps/CameraITS/tests/inprog/test_param_black_level_lock.py
blob: 7d0be921bd67f90eb4fa1594a78e27b4ea3c5dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import its.image
import its.device
import its.objects
import pylab
import os.path
import matplotlib
import matplotlib.pyplot
import numpy

def main():
    """Test that when the black level is locked, it doesn't change.

    Shoot with the camera covered (i.e.) dark/black. The test varies the
    sensitivity parameter and checks if the black level changes.
    """
    NAME = os.path.basename(__file__).split(".")[0]

    NUM_STEPS = 5

    req = {
        "android.blackLevel.lock": True,
        "android.control.mode": 0,
        "android.control.aeMode": 0,
        "android.control.awbMode": 0,
        "android.control.afMode": 0,
        "android.sensor.frameDuration": 0,
        "android.sensor.exposureTime": 10*1000*1000
        }

    # The most frequent pixel value in each image; assume this is the black
    # level, since the images are all dark (shot with the lens covered).
    modes = []

    with its.device.ItsSession() as cam:
        props = cam.get_camera_properties()
        sens_range = props['android.sensor.info.sensitivityRange']
        sensitivities = range(sens_range[0],
                              sens_range[1]+1,
                              int((sens_range[1] - sens_range[0]) / NUM_STEPS))
        for si, s in enumerate(sensitivities):
            req["android.sensor.sensitivity"] = s
            cap = cam.do_capture(req)
            yimg,_,_ = its.image.convert_capture_to_planes(cap)
            hist,_ = numpy.histogram(yimg*255, 256, (0,256))
            modes.append(numpy.argmax(hist))

            # Add this histogram to a plot; solid for shots without BL
            # lock, dashes for shots with BL lock
            pylab.plot(range(16), hist.tolist()[:16])

    pylab.xlabel("Luma DN, showing [0:16] out of full [0:256] range")
    pylab.ylabel("Pixel count")
    pylab.title("Histograms for different sensitivities")
    matplotlib.pyplot.savefig("%s_plot_histograms.png" % (NAME))

    # Check that the black levels are all the same.
    print "Black levels:", modes
    assert(all([modes[i] == modes[0] for i in range(len(modes))]))

if __name__ == '__main__':
    main()