humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | Changelog

recognize_qr_code

recognize_qr_code($path); - Распознать картинку с QR кодом

Функция на вход принимает параметры:

  • $path – путь к исходной картинке

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • результат – результат
  • пусто / null – ошибка

    Пример использования
    <?php
    // Scenario: Recognize QR code from an image file
    $xhe_host = getenv("RPABOT_HOST_URL");
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // Create QR code with email address
    $qrCodePath = "images/generated_qr_email.png";
    $qrText = "mailto:contact@example.com";
    $width = 250;
    $height = 250;
    
    echo "\nCreating QR code with email address...\n";
    $result = DOM::$image->create_qr_code($qrCodePath, $qrText, $width, $height);
    
    if ($result) {
        echo "QR code with email address created successfully!\n";
        echo "Email QR code image saved to: " . $qrCodePath . "\n";
    } else {
        echo "Failed to create QR code with email address\n";
    }
    
    // Example 1: Recognize the created QR code to verify it works
    if (file_exists($qrCodePath)) {
        echo "\nVerifying created QR code by recognizing it...\n";
        $recognizedText = DOM::$image->recognize_qr_code($qrCodePath);
    
        if ($recognizedText) {
            echo "QR code recognized successfully!\n";
            echo "Recognized text: " . $recognizedText . "\n";
    
            // Check if recognized text matches original
            if ($recognizedText === $qrText) {
                echo "Recognized text matches original text: " . $qrText . "\n";
            } else {
                echo "Warning: Recognized text does not match original text\n";
                echo "Original: " . $qrText . "\n";
                echo "Recognized: " . $recognizedText . "\n";
            }
        } else {
            echo "Failed to recognize created QR code\n";
        }
    }
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:3036"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>image.xxxxxxxxx</font><hr>")
    
    # путь к картинке
    path = "image/qr_code.png";
    
    # 1
    echo("\n1. Получим картинку с QR кодом : ");
    echo(image.get_qr_code(path,path+".qr_code.jpg"));
    
    # показать
    app.shell_execute("open",path+".qr_code.jpg");
    
    # 2
    echo("\n2. Распознаем картинку с QR кодом : ");
    echo(image.recognize_qr_code(path));
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = Environment.GetEnvironmentVariable("RPABOT_HOST_URL");
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>image.recognize_qr_code</font><hr>");
    										
    			// путь к картинке
    			var path = "image/qr_code.png";
    
    			// 1
    			echo("\n1. Получим картинку с QR кодом : ");
    			echo(image.get_qr_code(path,path+".qr_code.jpg"));
    
    			// показать
    			app.shell_execute("open",path+".qr_code.jpg");
    
    			// 2
    			echo("\n2. Распознаем картинку с QR кодом : ");
    			echo(image.recognize_qr_code(path));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:3035";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>image.add_image</font><hr>");
    
    // путь к картинке
    var path = "image/qr_code.png";
    
    // 1
    echo("\n1. Получим картинку с QR кодом : ");
    echo(image.get_qr_code(path,path+".qr_code.jpg"));
    
    // показать
    app.shell_execute("open",path+".qr_code.jpg");
    
    // 2
    echo("\n2. Распознаем картинку с QR кодом : ");
    echo(image.recognize_qr_code(path));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Image    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.