blob: fba4162dd2e2337e0aa0dd8655089992ede0a1e8 [file] [log] [blame]
Ruben Brunk370e2432014-10-14 18:33:23 -07001# 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
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 that converted YUV images and device JPEG images look the same.
25 """
26 NAME = os.path.basename(__file__).split(".")[0]
27
28 THRESHOLD_MAX_RMS_DIFF = 0.01
29
30 with its.device.ItsSession() as cam:
31 props = cam.get_camera_properties()
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -070032 its.caps.skip_unless(its.caps.compute_target_exposure(props))
Ruben Brunk370e2432014-10-14 18:33:23 -070033
34 e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
35 req = its.objects.manual_capture_request(s, e, True)
36
37 # YUV
38 size = its.objects.get_available_output_sizes("yuv", props)[0]
39 out_surface = {"width":size[0], "height":size[1], "format":"yuv"}
40 cap = cam.do_capture(req, out_surface)
41 img = its.image.convert_capture_to_rgb_image(cap)
42 its.image.write_image(img, "%s_fmt=yuv.jpg" % (NAME))
43 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
44 rgb0 = its.image.compute_image_means(tile)
45
46 # JPEG
47 size = its.objects.get_available_output_sizes("jpg", props)[0]
48 out_surface = {"width":size[0], "height":size[1], "format":"jpg"}
49 cap = cam.do_capture(req, out_surface)
50 img = its.image.decompress_jpeg_to_rgb_image(cap["data"])
51 its.image.write_image(img, "%s_fmt=jpg.jpg" % (NAME))
52 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
53 rgb1 = its.image.compute_image_means(tile)
54
55 rms_diff = math.sqrt(
56 sum([pow(rgb0[i] - rgb1[i], 2.0) for i in range(3)]) / 3.0)
57 print "RMS difference:", rms_diff
58 assert(rms_diff < THRESHOLD_MAX_RMS_DIFF)
59
60if __name__ == '__main__':
61 main()
62