openwines / computer-vision-bundle
为您的 Symfony 项目提供 Microsoft Computer Vision API 集成。
Requires
- guzzlehttp/guzzle: ^6.2
- league/csv: ^8.2
This package is not auto-updated.
Last update: 2024-09-14 20:04:20 UTC
README
"自1768年以来,Chéneau家族的酿酒师一直致力于Muscadet Sèvre et Maine AOC葡萄酒的酿造 www.vignoblescheneau.com。Château de la Cormerais是位于Monnières的一个中世纪古老的庄园,自1856年以来一直属于Chéneau家族。Château de la Cormerais Muscadet Sèvre et Maine Sur Lie经常获奖,是Chéneau家族在布列塔尼大区Marches地区的重要代表。在Château de la Cormerais,从父辈到子辈,一直传承着对葡萄酒的热爱。在酒庄装瓶,阳光明媚。BEAU-SOLEIL,44330 Mouzillon,布列塔尼,3 557090 013504"
服务介绍
通过 Microsoft's Computer Vision API,用户可以直接从 Symfony 项目中分析图像,使用光学字符识别来识别图像中的文本。
基于云的 Computer Vision API 为开发者提供访问高级图像处理算法的权限,并返回信息。通过上传图像或指定图像 URL,Microsoft Computer Vision 算法可以根据输入和用户选择以不同的方式分析视觉内容。
OCR 作为服务可用
- 在 Symfony 的依赖注入容器中可用
- 作为命令行工具,具有参数和选项(见下文)
支持的地区
OCR 支持的 21 种语言包括中文简体、中文繁体、捷克语、丹麦语、荷兰语、英语、芬兰语、法语、德语、希腊语、匈牙利语、意大利语、日语、韩语、挪威语、波兰语、葡萄牙语、俄语、西班牙语、瑞典语和土耳其语。
准确性
文本识别的准确性取决于图像质量。以下因素可能导致不准确的阅读:
- 模糊的图像
- 手写或草书文字
- 艺术字体样式
- 小的文字大小
- 复杂的背景、阴影或眩光覆盖文字或透视失真
- 在单词开头的字母过大或缺失
- 下标、上标或删除线文字
限制
在以文字为主的照片中,部分识别的单词可能导致假阳性。在某些照片中,特别是没有文字的照片,精度可能因图像类型而大不相同。
- 小的文字大小
- 复杂的背景、阴影或眩光覆盖文字或透视失真
- 在单词开头的字母过大或缺失
- 下标、上标或删除线文字
API 文档
API 使用条件
- 免费:每月最多5000次调用
- 限流:每秒10个事务
- 付费:每1000次调用1.50美元
获取 API 令牌不需要信用卡。
安装
下载 Bundle
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此 Bundle 的最新稳定版本
$ composer require openwines/computer-vision-bundle "dev-master"
此命令需要您已全局安装 Composer,如 Composer 文档的 安装章节 所述。
启用 Bundle
然后,通过将其添加到项目 app/AppKernel.php
文件中注册的 Bundle 列表中来启用该 Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new OpenWines\ComputerVisionBundle\OpenWinesComputerVisionBundle(), ); // ... } // ... }
然后创建您的 API 密钥: https://www.microsoft.com/cognitive-services/en-us/computer-vision-api
并将其复制到 app/config/parameters.yml
parameters: (...) microsoft_computer_vision.api_token: aSecretTokenNotToPushOnGithub
作为服务使用
此服务可在您的依赖注入容器中找到(openwines_computer_vision.client
)
$result = $this ->getContainer() ->get('openwines_computer_vision.client') ->process( $input->getArgument('source'), // a file or a folder $input->getArgument('lang') // fr, en, unk (auto-detect if unknown), etc. See doc link above );
在命令行中使用
基本用法:对一个文件或图像文件夹进行OCR处理,然后将结果输出或创建一个CSV文件,每行一个图像。
Usage: cv:ocr [options] [--] <source> <lang> Arguments: source base64 encoded, URL, or absolute path. Single image or folder. lang The BCP-47 language code of the text to be detected in the image. The default value is "unk", then the service will auto detect the language of the text in the image. Options: -o, --output=OUTPUT The optional CSV file output path -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -e, --env=ENV The environment name [default: "dev"] --no-debug Switches off debug mode -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: This command allows you to perform Optical Character Recognition (OCR) method over an image, to detect text in an image and extract recognized characters into a machine-usable character stream. the OCR results are returned include include text, bounding box for regions, lines and words Computer Vision API overview: https://www.microsoft.com/cognitive-services/en-us/computer-vision-api Computer Vision API documentation: https://westus.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc Example: php bin/console cv:ocr -o ./wines.csv vendor/openwines/computer-vision-bundle/src/OpenWines/ComputerVisionBundle/Resources/data/wines/ fr cat wines.csv