1#!/usr/bin/env python3

2# This file is part of Checkbox.

3#

4# Copyright 2020 Canonical Ltd.

5# Written by:

6# Jonathan Cave <jonathan.cave@canonical.com>

7#

8# Checkbox is free software: you can redistribute it and/or modify

9# it under the terms of the GNU General Public License version 3,

10# as published by the Free Software Foundation.

11#

12# Checkbox is distributed in the hope that it will be useful,

13# but WITHOUT ANY WARRANTY; without even the implied warranty of

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

15# GNU General Public License for more details.

16#

17# You should have received a copy of the GNU General Public License

18# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

19

20 import argparse

21 import os

22 import sys

23 import time

24

25 import picamera

26

27# resolutions and framerates corresponding to sensor modes at:

28# https://picamera.readthedocs.io/en/release-1.13/fov.html#camera-modes

29 test_res = [

30 ((1920, 1080), 2),

31 ((2592, 1944), 2),

32 ((2592, 1944), (1, 8)),

33 ((1296, 972), 5),

34 ((1296, 730), 20),

35 ((640, 480), 50),

36 ((640, 480), 80),

37]

38

39

40 def capture():

41 path = os.path.expandvars("$PLAINBOX_SESSION_SHARE")

42 print("Images will be written to:\n{}\n".format(path), flush=True)

43 for mode_no, (res, fr) in enumerate(test_res):

44 with picamera.PiCamera(resolution=res, framerate=fr) as camera:

45 print("Camera initialised, wait to settle...", flush=True)

46 time.sleep(2)

47 print("Resolution: {}".format(camera.resolution))

48 print("Framerate: {}".format(camera.framerate))

49 file = "picam_{}.jpg".format(mode_no + 1)

50 camera.capture(os.path.join(path, file))

51 print("Image {} captured\n".format(file))

52

53

54 def main():

55 parser = argparse.ArgumentParser(description="PiCamera Tests")

56 parser.add_argument("--device", default="/dev/vchiq", type=str)

57 args = parser.parse_args()

58 print("Resolutions test on device: {}".format(args.device), flush=True)

59 return capture()

60

61

62 if __name__ == "__main__":

63 sys.exit(main())