blob: bfa6a28c0d2419607c9a3397420389fe0768dcf0 [file] [log] [blame]
Ruben Brunk370e2432014-10-14 18:33:23 -07001# 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 RAW and YUV outputs.
25 """
26 NAME = os.path.basename(__file__).split(".")[0]
27
Yin-Chia Yeh3b1763a2014-10-22 10:59:13 -070028 THRESHOLD_MAX_RMS_DIFF = 0.035
Ruben Brunk370e2432014-10-14 18:33:23 -070029
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) and
Chien-Yu Chen34fa85d2014-10-22 16:58:08 -070033 its.caps.raw16(props) and
34 its.caps.per_frame_control(props))
Ruben Brunk370e2432014-10-14 18:33:23 -070035
36 # Use a manual request with a linear tonemap so that the YUV and RAW
37 # should look the same (once converted by the its.image module).
38 e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
Yin-Chia Yeh9afa7252015-05-08 15:05:50 -070039 req = its.objects.manual_capture_request(s, e, True, props)
Ruben Brunk370e2432014-10-14 18:33:23 -070040
Yin-Chia Yehd511ded2015-09-03 14:46:57 -070041 max_raw_size = \
42 its.objects.get_available_output_sizes("raw", props)[0]
43 w,h = its.objects.get_available_output_sizes(
44 "yuv", props, (1920, 1080), max_raw_size)[0]
45 out_surfaces = [{"format":"raw"},
46 {"format":"yuv", "width":w, "height":h}]
47 cap_raw, cap_yuv = cam.do_capture(req, out_surfaces)
Ruben Brunk370e2432014-10-14 18:33:23 -070048
49 img = its.image.convert_capture_to_rgb_image(cap_yuv)
50 its.image.write_image(img, "%s_yuv.jpg" % (NAME), True)
51 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
52 rgb0 = its.image.compute_image_means(tile)
53
54 # Raw shots are 1/2 x 1/2 smaller after conversion to RGB, so scale the
55 # tile appropriately.
56 img = its.image.convert_capture_to_rgb_image(cap_raw, props=props)
57 its.image.write_image(img, "%s_raw.jpg" % (NAME), True)
58 tile = its.image.get_image_patch(img, 0.475, 0.475, 0.05, 0.05)
59 rgb1 = its.image.compute_image_means(tile)
60
61 rms_diff = math.sqrt(
62 sum([pow(rgb0[i] - rgb1[i], 2.0) for i in range(3)]) / 3.0)
63 print "RMS difference:", rms_diff
64 assert(rms_diff < THRESHOLD_MAX_RMS_DIFF)
65
66if __name__ == '__main__':
67 main()
68