From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id uAXhLlntnWTPBgAASxT56A (envelope-from ) for ; Thu, 29 Jun 2023 22:45:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2PgEL1ntnWT7EgEAauVa8A (envelope-from ) for ; Thu, 29 Jun 2023 22:45:13 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8622FAF53 for ; Thu, 29 Jun 2023 22:45:13 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEyVl-0006GL-FY; Thu, 29 Jun 2023 16:45:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEyVi-0006Fm-1D for guix-patches@gnu.org; Thu, 29 Jun 2023 16:45:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEyVh-0007V5-OG for guix-patches@gnu.org; Thu, 29 Jun 2023 16:45:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qEyVh-0006GS-L7 for guix-patches@gnu.org; Thu, 29 Jun 2023 16:45:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64356] [PATCH 2/4] marionette: Allow passing custom OCR arguments. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 29 Jun 2023 20:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64356 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64356@debbugs.gnu.org Cc: Bruno Victal Received: via spool by 64356-submit@debbugs.gnu.org id=B64356.168807147323990 (code B ref 64356); Thu, 29 Jun 2023 20:45:01 +0000 Received: (at 64356) by debbugs.gnu.org; 29 Jun 2023 20:44:33 +0000 Received: from localhost ([127.0.0.1]:54131 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qEyVF-0006Es-08 for submit@debbugs.gnu.org; Thu, 29 Jun 2023 16:44:33 -0400 Received: from smtpmciv5.myservices.hosting ([185.26.107.241]:58974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qEyVC-0006Eb-DI for 64356@debbugs.gnu.org; Thu, 29 Jun 2023 16:44:31 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpmciv5.myservices.hosting (Postfix) with ESMTP id 99E1120D81 for <64356@debbugs.gnu.org>; Thu, 29 Jun 2023 22:44:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id E433180060; Thu, 29 Jun 2023 22:44:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id t43YrL3atSSU; Thu, 29 Jun 2023 22:44:28 +0200 (CEST) Received: from guix-nuc.home.arpa (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 66A3980097; Thu, 29 Jun 2023 22:44:28 +0200 (CEST) From: Bruno Victal Date: Thu, 29 Jun 2023 21:44:20 +0100 Message-Id: <60f2dc235aed7d2cd359a565e66b9ddf6f2371db.1688071435.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1688071513; a=rsa-sha256; cv=none; b=q+H7nTutQI48YboOQh7MVSMxqRv7umdwy6qza6eZwWdXBWgKvo6zXhiXefTNZkATyqUwNP eamdNAzQ/Qm382IyHrgh87zlv7USbERWH7G5RjiCfgHOne4Si5my9pK/OhBGiLzwCqe5FE XWCz6CTv9vk84RO076rkBCRkEf6cXjpcUnvI2DCydwfexLLGCkAt4Ca7nt+b4BqrbZTYmx MrM7dnquACfYpzx0qKW/Oa+dGb7D4tWkqyZcfAHfLd6hN5SX8pXAnZ9d/r19gj/cmF3tPD /e25fGFzfzZlsTa9jbW9dpcEVB3EH2Cqcsexq6FmqBWrdhYJevBcI83f/6hieQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1688071513; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=tcz81DyJ9D6Lv3VmrLdxZ6/dkHPKZQsl3zYXpUo5qug=; b=SqCpJY9W7z+nHFMhjlwMaRMbb7bmNgfo32arjontrDFvHs2b2p9iPv05Ny/eFPWuaF/Fp/ zZjrIJYnq0DQ1rOtF7csyy3r+nJ7APLXvNV8LNcTEh1WKYBvTJIGev9I9ImTz9R0wzbz/K Wm2L3O/A8LCRwi/BzPVcT28fsGiO5yKby5zMi+ntxmWNhhbKYadXfz8mVc2wnNRjA0z8Lm XeRUP1FxpwGC3aW6GAgLlSqP+x9tZBcYhKBNa3f7eggBonqYeX8Dm5PQWmv5evi8R9t3Zk n+cYiMZ2JkB5uNOeyJPXg5sjJfGObPELqO/lWUxC/WM8M0AlqFVUzqLLOQgIYg== Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -2.56 X-Spam-Score: -2.56 X-Migadu-Queue-Id: 8622FAF53 X-TUID: +ojJFmWynKOn * gnu/build/marionette.scm (invoke-ocrad-ocr, invoke-tesseract-ocr) (marionette-screen-text): New 'ocr-arguments' argument. --- gnu/build/marionette.scm | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm index b8fba61d06..5621896198 100644 --- a/gnu/build/marionette.scm +++ b/gnu/build/marionette.scm @@ -287,23 +287,30 @@ (define (marionette-control command marionette) ;; The "quit" command terminates QEMU immediately, with no output. (unless (string=? command "quit") (wait-for-monitor-prompt monitor))))) -(define* (invoke-ocrad-ocr image #:key (ocrad "ocrad")) +(define* (invoke-ocrad-ocr image #:key (ocrad "ocrad") ocr-arguments) "Invoke the OCRAD command on image, and return the recognized text." - (let* ((pipe (open-pipe* OPEN_READ ocrad "-i" "-s" "10" image)) + (let* ((arguments (or ocr-arguments + "--invert --scale 10")) + (command (string-join (list ocrad ocr-arguments image))) + (pipe (open-input-pipe command)) (text (get-string-all pipe))) (unless (zero? (close-pipe pipe)) (error "'ocrad' failed" ocrad)) text)) -(define* (invoke-tesseract-ocr image #:key (tesseract "tesseract")) +(define* (invoke-tesseract-ocr image #:key (tesseract "tesseract") + ocr-arguments) "Invoke the TESSERACT command on IMAGE, and return the recognized text." (let* ((output-basename (tmpnam)) - (output-basename* (string-append output-basename ".txt"))) + (output-basename* (string-append output-basename ".txt")) + (arguments (cons* image output-basename + (or (and=> ocr-arguments list) + '())))) (dynamic-wind (const #t) (lambda () (let ((exit-val (status:exit-val - (system* tesseract image output-basename)))) + (apply system* tesseract arguments)))) (unless (zero? exit-val) (error "'tesseract' failed" tesseract)) (call-with-input-file output-basename* get-string-all))) @@ -311,7 +318,8 @@ (define* (invoke-tesseract-ocr image #:key (tesseract "tesseract")) (false-if-exception (delete-file output-basename)) (false-if-exception (delete-file output-basename*)))))) -(define* (marionette-screen-text marionette #:key (ocr "ocrad")) +(define* (marionette-screen-text marionette #:key (ocr "ocrad") + ocr-arguments) "Take a screenshot of MARIONETTE, perform optical character recognition (OCR), and return the text read from the screen as a string, along the screen dump image used. Do this by invoking OCR, which should be the file @@ -324,14 +332,19 @@ (define* (marionette-screen-text marionette #:key (ocr "ocrad")) ;; Process it via the OCR. (cond ((string-contains ocr "ocrad") - (values (invoke-ocrad-ocr image #:ocrad ocr) image)) + (values (invoke-ocrad-ocr image + #:ocrad ocr + #:ocr-arguments ocr-arguments) image)) ((string-contains ocr "tesseract") - (values (invoke-tesseract-ocr image #:tesseract ocr) image)) + (values (invoke-tesseract-ocr image + #:tesseract ocr + #:ocr-arguments ocr-arguments) image)) (else (error "unsupported ocr command")))) (define* (wait-for-screen-text marionette predicate #:key (ocr "ocrad") + ocr-arguments (timeout 30) pre-action post-action) @@ -359,7 +372,10 @@ (define* (wait-for-screen-text marionette predicate 'ocr-text: last-text 'screendump: screendump-backup)) (let* ((_ (and (procedure? pre-action) (pre-action))) - (text screendump (marionette-screen-text marionette #:ocr ocr)) + (text screendump + (marionette-screen-text marionette + #:ocr ocr + #:ocr-arguments ocr-arguments)) (_ (and (procedure? post-action) (post-action))) (result (predicate text))) (cond (result -- 2.39.2