1# Copyright 2015 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
15import its.image
16import its.caps
17import its.device
18import its.objects
19import its.target
20import os.path
21import math
22
23def main():
24    """Test capturing some rawstats data.
25    """
26    NAME = os.path.basename(__file__).split(".")[0]
27
28    with its.device.ItsSession() as cam:
29
30        cam.do_3a(do_af=False);
31        req = its.objects.auto_capture_request()
32
33        for (gw,gh) in [(16,16)]:#,(4080,1)]:
34            cap = cam.do_capture(req,
35                {"format":"rawStats","gridWidth":gw,"gridHeight":gh})
36            mean_image, var_image = its.image.unpack_rawstats_capture(cap)
37
38            if gw > 1 and gh > 1:
39                h,w,_ = mean_image.shape
40                for ch in range(4):
41                    m = mean_image[:,:,ch].reshape(h,w,1)/1023.0
42                    v = var_image[:,:,ch].reshape(h,w,1)
43                    its.image.write_image(m, "%s_mean_ch%d.jpg" % (NAME,ch), True)
44                    its.image.write_image(v, "%s_var_ch%d.jpg" % (NAME,ch), True)
45
46if __name__ == '__main__':
47    main()
48
49