Patch Detail
Show a patch.
GET /api/1.1/patches/16181/?format=api
{ "id": 16181, "url": "https://patchwork.libcamera.org/api/1.1/patches/16181/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16181/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220608072418.13154-3-tomi.valkeinen@ideasonboard.com>", "date": "2022-06-08T07:24:16", "name": "[libcamera-devel,v5,2/4] py: examples: Add simple-capture.py", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "37920d742fcd7b06ecda655134db52bc0295bcb3", "submitter": { "id": 109, "url": "https://patchwork.libcamera.org/api/1.1/people/109/?format=api", "name": "Tomi Valkeinen", "email": "tomi.valkeinen@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16181/mbox/", "series": [ { "id": 3165, "url": "https://patchwork.libcamera.org/api/1.1/series/3165/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3165", "date": "2022-06-08T07:24:14", "name": "More misc Python patches", "version": 5, "mbox": "https://patchwork.libcamera.org/series/3165/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16181/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16181/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E3FAAC3273\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 8 Jun 2022 07:24:45 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A5C5A6563B;\n\tWed, 8 Jun 2022 09:24:44 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 30B5865631\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 8 Jun 2022 09:24:41 +0200 (CEST)", "from deskari.lan (91-156-85-209.elisa-laajakaista.fi\n\t[91.156.85.209])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 670F2B91;\n\tWed, 8 Jun 2022 09:24:40 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654673084;\n\tbh=4RuUVtJkrvfqg0VFAifC8duITz905YHYLMuO/ncpeQM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=WSSuQ5M6aAKa4SdocVbLvDJAiGJSC+X/0ZkXuMkmszsaong0W/i9zhqKPPT9d5wpn\n\t4Eez0NBSfGz47rdz/lyunVtu9fOg9IK63sqodifpz/fE+fvoEhUB76GKVGkgoeklSF\n\tNDZ+3ykkKD3u/OMXDkc3WymSGxYZSqDONTgR3bWM5TMeJHcD0d27nfGp/X6FQfUyAW\n\trAonh/Lr8i1fef1uBTbARFlEecxxPeLbMF4qMuQmlWkFwj8B3sIy7g4JcJhWv0lD7q\n\tUkdR+GdItxtzug6bmdiiB3HaEabIugVhNvpyy4KE3iffuvIcvmeCcl3Z4vETvG8iMu\n\ta0IBZ31dFLACQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1654673080;\n\tbh=4RuUVtJkrvfqg0VFAifC8duITz905YHYLMuO/ncpeQM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ih10KoYL3FqSnIrT75RUP+zgeAns5Igezn6Grf5SWpgbzRKgHuFUcoNm7dhu2kAsF\n\tevkIRBMrhe5zajYn9up9sLTjmHMOuBkD3uJPtCl0kjwNESAPxZyY9qnKlbppXZobOK\n\tUDTiu7f/oMKnQGgAMVeBPPsKSoICIQ9EQgypOgXc=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Ih10KoYL\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>", "Date": "Wed, 8 Jun 2022 10:24:16 +0300", "Message-Id": "<20220608072418.13154-3-tomi.valkeinen@ideasonboard.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20220608072418.13154-1-tomi.valkeinen@ideasonboard.com>", "References": "<20220608072418.13154-1-tomi.valkeinen@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 2/4] py: examples: Add simple-capture.py", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add an example to showcase the more-or-less minimal capture case.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/py/examples/simple-capture.py | 162 ++++++++++++++++++++++++++++++\n 1 file changed, 162 insertions(+)\n create mode 100755 src/py/examples/simple-capture.py", "diff": "diff --git a/src/py/examples/simple-capture.py b/src/py/examples/simple-capture.py\nnew file mode 100755\nindex 00000000..a6a9b33e\n--- /dev/null\n+++ b/src/py/examples/simple-capture.py\n@@ -0,0 +1,162 @@\n+#!/usr/bin/env python3\n+\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n+\n+# A simple capture example showing:\n+# - How to setup the camera\n+# - Capture certain number of frames in a blocking manner\n+# - How to stop the camera\n+#\n+# This simple example is, in many ways, too simple. The purpose of the example\n+# is to introduce the concepts. A more realistic example is given in\n+# simple-continuous-capture.py.\n+\n+import argparse\n+import libcamera as libcam\n+import sys\n+\n+# Number of frames to capture\n+TOTAL_FRAMES = 30\n+\n+\n+def main():\n+ parser = argparse.ArgumentParser()\n+ parser.add_argument('-c', '--camera', type=str, default='1',\n+ help='Camera index number (starting from 1) or part of the name')\n+ parser.add_argument('-f', '--format', type=str, help='Pixel format')\n+ parser.add_argument('-s', '--size', type=str, help='Size (\"WxH\")')\n+ args = parser.parse_args()\n+\n+ cm = libcam.CameraManager.singleton()\n+\n+ try:\n+ if args.camera.isnumeric():\n+ cam_idx = int(args.camera)\n+ cam = next((cam for i, cam in enumerate(cm.cameras) if i + 1 == cam_idx))\n+ else:\n+ cam = next((cam for cam in cm.cameras if args.camera in cam.id))\n+ except Exception:\n+ print(f'Failed to find camera \"{args.camera}\"')\n+ return -1\n+\n+ # Acquire the camera for our use\n+\n+ ret = cam.acquire()\n+ assert ret == 0\n+\n+ # Configure the camera\n+\n+ cam_config = cam.generate_configuration([libcam.StreamRole.Viewfinder])\n+\n+ stream_config = cam_config.at(0)\n+\n+ if args.format:\n+ fmt = libcam.PixelFormat(args.format)\n+ stream_config.pixel_format = fmt\n+\n+ if args.size:\n+ w, h = [int(v) for v in args.size.split('x')]\n+ stream_config.size = libcam.Size(w, h)\n+\n+ ret = cam.configure(cam_config)\n+ assert ret == 0\n+\n+ print(f'Capturing {TOTAL_FRAMES} frames with {stream_config}')\n+\n+ stream = stream_config.stream\n+\n+ # Allocate the buffers for capture\n+\n+ allocator = libcam.FrameBufferAllocator(cam)\n+ ret = allocator.allocate(stream)\n+ assert ret > 0\n+\n+ num_bufs = len(allocator.buffers(stream))\n+\n+ # Create the requests and assign a buffer for each request\n+\n+ reqs = []\n+ for i in range(num_bufs):\n+ # Use the buffer index as the cookie\n+ req = cam.create_request(i)\n+\n+ buffer = allocator.buffers(stream)[i]\n+ ret = req.add_buffer(stream, buffer)\n+ assert ret == 0\n+\n+ reqs.append(req)\n+\n+ # Start the camera\n+\n+ ret = cam.start()\n+ assert ret == 0\n+\n+ # frames_queued and frames_done track the number of frames queued and done\n+\n+ frames_queued = 0\n+ frames_done = 0\n+\n+ # Queue the requests to the camera\n+\n+ for req in reqs:\n+ ret = cam.queue_request(req)\n+ assert ret == 0\n+ frames_queued += 1\n+\n+ # The main loop. Wait for the queued Requests to complete, process them,\n+ # and re-queue them again.\n+\n+ while frames_done < TOTAL_FRAMES:\n+ # cm.get_ready_requests() blocks until there is an event and returns\n+ # all the ready requests. Here we should almost always get a single\n+ # Request, but in some cases there could be multiple or none.\n+\n+ reqs = cm.get_ready_requests()\n+\n+ for req in reqs:\n+ frames_done += 1\n+\n+ buffers = req.buffers\n+\n+ # A ready Request could contain multiple buffers if multiple streams\n+ # were being used. Here we know we only have a single stream,\n+ # and we use next(iter()) to get the first and only buffer.\n+\n+ assert len(buffers) == 1\n+\n+ stream, fb = next(iter(buffers.items()))\n+\n+ # Here we could process the received buffer. In this example we only\n+ # print a few details below.\n+\n+ meta = fb.metadata\n+\n+ print(\"seq {:3}, bytes {}, frames queued/done {:3}/{:<3}\"\n+ .format(meta.sequence,\n+ '/'.join([str(p.bytes_used) for p in meta.planes]),\n+ frames_queued, frames_done))\n+\n+ # If we want to capture more frames we need to queue more Requests.\n+ # We could create a totally new Request, but it is more efficient\n+ # to reuse the existing one that we just received.\n+ if frames_queued < TOTAL_FRAMES:\n+ req.reuse()\n+ cam.queue_request(req)\n+ frames_queued += 1\n+\n+ # Stop the camera\n+\n+ ret = cam.stop()\n+ assert ret == 0\n+\n+ # Release the camera\n+\n+ ret = cam.release()\n+ assert ret == 0\n+\n+ return 0\n+\n+\n+if __name__ == '__main__':\n+ sys.exit(main())\n", "prefixes": [ "libcamera-devel", "v5", "2/4" ] }