From patchwork Fri Sep 1 15:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18975 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9957DC32B7 for ; Fri, 1 Sep 2023 15:03:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EE12628F3; Fri, 1 Sep 2023 17:03:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1693580580; bh=OsMSzhJr2Feh6IYM0vX5jRQDQ74eSJ0ryvRr2HrJTyA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jdhLiOZ/pg5ODiVEMKPx6ZhQbg9CkW4xwa6D8151rDIe3XC62CztnCXyhcTIfyWtR xrn21kjkClitEkYCEHXfsTaR2nWkhE5zCXMvMEsNbhaInDZp6kEkg10AHCM0g0G6Pm p6XywOQ3HY0ETbTkIQraCcpmN0lCpuqCaD2tsvohhjurIphU6qRyzcCibVnU6iFYTI lSK/rQUpQy6vSOEbRyBqGc3y/P7P6rN9nBCvuWkqj+lBgeQmYeTczWdwZVvLkpWCWs EJvELgPwiiFtfj3Vq6OJcuue0B8nuPaPkDzF3SJPULtKDl7QCBQnj3Rne7pCG7u3Zm GOd+bZCJzONPg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC88E628F9 for ; Fri, 1 Sep 2023 17:02:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="milbAz24"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A51A61288; Fri, 1 Sep 2023 17:01:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1693580492; bh=OsMSzhJr2Feh6IYM0vX5jRQDQ74eSJ0ryvRr2HrJTyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=milbAz24jomymGeU32tQ6rrW9eakXV7lgRkK1bZK8d0a2xn/L5gaSZrhoJp8HQsPf YGQ5HojDbaoNZUlPZbksv8haR3i3GwYvG6JV2fLOb5VPTQqvrry9NNDTU+VBXk7b11 u/FPjeSjH7PzmhBVnrRRO754zAq5rP0Ht4mj9BZM= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 Sep 2023 17:02:15 +0200 Message-Id: <20230901150215.11585-13-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230901150215.11585-1-jacopo.mondi@ideasonboard.com> References: <20230901150215.11585-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 12/12] py: cam: Add option to set stream orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '--orientation|-o' option to the Python version of the cam test application to set an orientation to the image stream. Supported values are: - Rot180: Rotate 180 degrees - Flip: vertical flip - Mirror: horizontal flip Signed-off-by: Jacopo Mondi --- src/py/cam/cam.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index a2a115c164b4..84d8ca1716fd 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -23,6 +23,7 @@ class CameraContext: opt_metadata: bool opt_save_frames: bool opt_capture: int + opt_orientation: str stream_names: dict[libcam.Stream, str] streams: list[libcam.Stream] @@ -146,6 +147,20 @@ class CameraContext: if 'pixelformat' in stream_opts: stream_config.pixel_format = libcam.PixelFormat(stream_opts['pixelformat']) + if self.opt_orientation is not None: + orientation_map = { + 'Rot180': libcam.Orientation.Rotate180, + 'Mirror': libcam.Orientation.Rotate0Flip, + 'Flip': libcam.Orientation.Rotate180Flip, + } + + orient = orientation_map.get(self.opt_orientation, None) + if orient is None: + print('Bad orientation: ', self.opt_orientation) + sys.exit(-1) + + camconfig.orientation = orient + stat = camconfig.validate() if stat == libcam.CameraConfiguration.Status.Invalid: @@ -385,6 +400,7 @@ def main(): parser.add_argument('--metadata', nargs=0, type=bool, action=CustomAction, help='Print the metadata for completed requests') parser.add_argument('--strict-formats', type=bool, nargs=0, action=CustomAction, help='Do not allow requested stream format(s) to be adjusted') parser.add_argument('-s', '--stream', nargs='+', action=CustomAction) + parser.add_argument('-o', '--orientation', help='Desired image orientation (Rot180, Mirror, Flip)') args = parser.parse_args() cm = libcam.CameraManager.singleton() @@ -408,6 +424,10 @@ def main(): ctx.opt_metadata = args.metadata.get(cam_idx, False) ctx.opt_strict_formats = args.strict_formats.get(cam_idx, False) ctx.opt_stream = args.stream.get(cam_idx, ['role=viewfinder']) + if args.orientation is not None: + ctx.opt_orientation = args.orientation + else: + ctx.opt_orientation = None contexts.append(ctx) for ctx in contexts: