• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 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 a single frame as both RAW10 and YUV outputs.
25    """
26    NAME = os.path.basename(__file__).split(".")[0]
27
28    THRESHOLD_MAX_RMS_DIFF = 0.02
29
30    with its.device.ItsSession() as cam:
31        props = cam.get_camera_properties()
32
33        if (not its.caps.compute_target_exposure(props) or
34            not its.caps.raw10(props)):
35            print "Test skipped"
36            return
37
38        # Use a manual request with a linear tonemap so that the YUV and RAW
39        # should look the same (once converted by the its.image module).
40        e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
41        req = its.objects.manual_capture_request(s, e, True)
42
43        cap_raw, cap_yuv = cam.do_capture(req,
44                [{"format":"raw10"}, {"format":"yuv"}])
45
46        img = its.image.convert_capture_to_rgb_image(cap_yuv)
47        its.image.write_image(img, "%s_yuv.jpg" % (NAME), True)
48        tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
49        rgb0 = its.image.compute_image_means(tile)
50
51        # Raw shots are 1/2 x 1/2 smaller after conversion to RGB, so scale the
52        # tile appropriately.
53        img = its.image.convert_capture_to_rgb_image(cap_raw, props=props)
54        its.image.write_image(img, "%s_raw.jpg" % (NAME), True)
55        tile = its.image.get_image_patch(img, 0.475, 0.475, 0.05, 0.05)
56        rgb1 = its.image.compute_image_means(tile)
57
58        rms_diff = math.sqrt(
59                sum([pow(rgb0[i] - rgb1[i], 2.0) for i in range(3)]) / 3.0)
60        print "RMS difference:", rms_diff
61        assert(rms_diff < THRESHOLD_MAX_RMS_DIFF)
62
63if __name__ == '__main__':
64    main()
65
66