<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpcfdi / image-captcha-resolver-boxfactura-ai example snippets
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\CaptchaImage;
use PhpCfdi\ImageCaptchaResolver\UnableToResolveCaptchaException;
/** @var string $theImgElementSrcAtributte */
$image = CaptchaImage::newFromInlineHtml($theImgElementSrcAtributte);
// Creación del resolvedor
$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$resolver = BoxFacturaAIResolver::createFromConfigs($configsFile);
try {
$answer = $resolver->resolve($image);
} catch (UnableToResolveCaptchaException $exception) {
echo "No se pudo resolver el captcha: {$exception->getMessage()}", PHP_EOL;
return;
}
echo "Respuesta del captcha: {$answer->getValue()}", PHP_EOL;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\ConfigsReader;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Processor;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Settings;
$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$reader = new ConfigsReader();
$settings = $reader->settingsFromFile($configsFile);
$processor = Processor::createFromSettings($settings);
$image = 'storage/captcha.png';
$result = $processor->resolveImageFile($image);
use Imagine\Imagick\Imagine as ImagineImagick;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\ConfigsReader;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Processor;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Settings;
use OnnxRuntime\InferenceSession;
\OnnxRuntime\FFI::$lib = '/usr/lib/x86_64-linux-gnu/libonnxruntime.so';
$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$reader = new ConfigsReader();
$settings = $reader->settingsFromFile($configsFile);
$onnxSession = new InferenceSession($settings->onnxModel, providers: ['CUDAExecutionProvider']);
$imagineEngine = new ImagineImagick();
$processor = new Processor(
$settings->imageWidth,
$settings->imageHeight,
$settings->alphabetArray,
$onnxSession,
$imagineEngine;
);
$resolver = new BoxFacturaAIResolver($processor);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.