From patchwork Tue Apr 25 02:04:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Naur X-Patchwork-Id: 18547 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 90B50C3272 for ; Tue, 25 Apr 2023 02:04:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A57DB627DF; Tue, 25 Apr 2023 04:04:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1682388276; bh=vh7bJtuFR+L5SCKvv61oS0a1V8Ci4Y16TnGwBORPWP4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Knq4aC1c2cs09fQXQ1kVQVLCTx+hk4oRFSREgwmqjoEhjY4Hu8MWE3OJKZxjQv930 dRLwkzzHnfDOH6CHTzdP4cD8ccDnqGvECD6dtbBhp2/HQhIQFgrayYAoJ0OW3b3Hy2 1f3Ijl/Nv9/ujh+bwqjCu/LPHOjGNIitGMiceafmCIoi7FUbRQZwVWePjEOXDegDkd 8D8SWH4NxUb9J3u/NfmOD7BWbbvOZsIkKSz58EE/2+p9cNllwRiucwm/sQB302g9Se kpwpiWWHvcLgmnN5XtFYECEeM8AqqUjpMAKji/jCjQmVV6kkLEE4nvhnSW4S7ttg2B uvfnk9jFS8zTw== Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5848B627CD for ; Tue, 25 Apr 2023 04:04:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=eliasnaur.com header.i=@eliasnaur.com header.b="sdcoOp+U"; dkim-atps=neutral Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-3ef34e948b1so24967061cf.2 for ; Mon, 24 Apr 2023 19:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eliasnaur.com; s=google; t=1682388273; x=1684980273; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=xJ64r6InKXAeawxbufiD/g2pk1DhrPgFioB7AtJhySA=; b=sdcoOp+UF/AAnxa8Ndav8HlFWHL3IdmbD31JPUYJZ8Qbau5Rki3QBp2ds2kRU8haSI w4LK2KsP/00d8m0TpnrN70VBAd+W8DgtqsGecuwEwBe458ZMALX3/3EuwyDZCmHAWAYq yl1O0/2khBEy0aYifarJ6zGO58NWHaEZEYEfNEyGVz68xW4by69p8BLVziHACA7VJ5GJ xhgbeVNse+K8tSGnRGx+11Ye/Y/sM63tEHvZVuCSfvDLgFyueSnEElX1j4v/pubogVyT 8HdXQSbGpKdNoxC18hlalIv4Lk4Jx+42gpkp0VO+lKYVnUpubUDHDI1tstZIMXi4S7bV /y0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682388273; x=1684980273; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xJ64r6InKXAeawxbufiD/g2pk1DhrPgFioB7AtJhySA=; b=E7ONBJEn1n+4iP7MSOs/GXIptDDs/sQbhKWj2vNffjAZxqEzHQi2FwfEa+4LLR/icc /gT+TuNeDjr6XmX9G8MhuTaI5yPicGEZDs2XUCGR8LvOaA/7rMiPBUyXe09KbCvLUdK2 RlOW4VV0TojkCiFUKhvv0zaLzrPUh/4da/o9819T1pol6fDElpq+DC8/H4p2vR9TNpIk tIze+rpdl6cWkX5cGwYXUSBKuQxNeXbRbW9hO9Olmr6bdTbusrvwicjfY7dJFDgqF/wZ CFVuBuCOR+LTDvyMebg0eLuyMrt4fxVljEOgF2WdYAYBBWsAZFJEho44NEU9a3KEVCbD 65jQ== X-Gm-Message-State: AAQBX9fjkDqzRtO4CQ6XIFjuRGD9ZDqDqR6vguRxtctE++i98CAX4kA8 uN8aG9uid7JGtQ6sTLZ1ZGS9r92hW8raj1V1oLgk0CBfyyasjym8lxQ= X-Google-Smtp-Source: AKy350YTG1Aq2Gubix2sVzs6/UBC54xPRt+pBmmO9QxANuOHoLWcHyOT1sCh0yN9uQxTiVcw5TjJH7Cky4GxsWDYaUA= X-Received: by 2002:a05:622a:64a:b0:3e6:59c2:cbae with SMTP id a10-20020a05622a064a00b003e659c2cbaemr26793421qtb.34.1682388272795; Mon, 24 Apr 2023 19:04:32 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 24 Apr 2023 20:04:22 -0600 Message-ID: To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] Suboptimal resolution for digital zoom (controls::ScalerCrop) 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: Elias Naur via libcamera-devel From: Elias Naur Reply-To: Elias Naur Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Hi, I'd like to squeeze out as much resolution as possible from my Raspberry Pi camera v1 for scanning QR codes. The camera has a fixed focus at ~50cm from the lens, so the resolution gain from moving the QR codes closer is lost to blur from the loss of focus. My current strategy is to scan codes at a distance, but use the considerable resolution of the sensor (~2500x1900) to gain enough resolution for successful scans. However, I fail to find any way to achieve that with libcamera. I tried three options, all suboptimal: 1. Configure the camera for full resolution and crop to a smaller section in my program. That works surprisingly well, except that the white-balance etc. algorithms run on the full image and not just the cropped part. 2. Configure the camera for full resolution and set controls::ScalerCrop to the area of interest. This seems to fix the white-balance algorithms, but results in the cropped area being *upscaled* to full resolution when I receive them. Scanning for QR codes at full resolution is way too slow on a RPi Zero. 3. Configure the camera for the same resolution of the area of interest, and set controls::ScalerCrop. This is efficient, but the sensor is configured for the low resolution and thus ruins the resolution gain. Questions: 1. Is there another way? 2. The following hack works for me, findBestFormat(data->sensorFormats_, Size{2592,1944}, bitDepth); const RPiCameraConfiguration *rpiConfig = static_cast(config); ret = data->sensor_->setFormat(&sensorFormat, rpiConfig->combinedTransform_); if (ret) Would a similar change that *always* uses the full sensor resolution be acceptable? I can't discern any performance issues between full resolution and lower resolution. 3. If the above fix is unacceptable, what is the right way to fix this issue in libcamera? Thanks, Elias diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 00600441..6ed81dc1 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -842,7 +842,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * request, and apply it to the sensor with the cached transform, if * any. */ - V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize, bitDepth); + V4L2SubdeviceFormat sensorFormat =