接入阿里云识别技术,实现陪玩平台源码图片文字识别
为了优化用户功能体验,陪玩平台源码实现了图片文字识别的功能,这样用户就可以直接获取文字,不用浪费时间在线编辑。陪玩平台源码接入了阿里云通用文字识别技术,实现图片文字在线识别,下面就介绍一下阿里云图片文字识别的功能案例:
一、代码示例
<?php // This file is auto-generated, don't edit it. Thanks. namespace AlibabaCloud\SDK\Sample; use AlibabaCloud\SDK\Ocrapi\V20210707\Ocrapi; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\SDK\Ocrapi\V20210707\Models\RecognizeHandwritingRequest; class Sample { /** * 使用AK&SK初始化账号Client * @param string $accessKeyId * @param string $accessKeySecret * @return Ocrapi Client */ public static function createClient($accessKeyId, $accessKeySecret){ $config = new Config([ // 您的AccessKey ID "accessKeyId" => $accessKeyId, // 您的AccessKey Secret "accessKeySecret" => $accessKeySecret ]); // 访问的域名 $config->endpoint = "ocr-api.cn-hangzhou.aliyuncs.com"; return new Ocrapi($config); } /** * @param string[] $args * @return void */ public static function main($args){ $client = self::createClient("accessKeyId", "accessKeySecret"); $recognizeHandwritingRequest = new RecognizeHandwritingRequest([]); // 复制代码运行请自行打印 API 的返回值 $client->recognizeHandwriting($recognizeHandwritingRequest); } } $path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php'; if (file_exists($path)) { require_once $path; } Sample::main(array_slice($argv, 1));
返回文件格式:
{ "RequestId" : "4AA3FA7B-CB2D-4314-B812-A598B540BADA", "Data" : "{\"content\":\"炼句 提问方式 1.请赏析诗歌某一联(句) 2.赏析某一联(句)的妙处 3.请赏析诗歌某一联1句)的表达效果 常规答题思路 1.手法: 1写景的句子侧重于写景手法(感官、角度.动静、虚实、典型画面、寓情于景等) ②写人的句子侧重于写人手法(动作、心理、肖像、细节等) ③抒情的句子侧重于抒情方式(直抒胸意、借景抒情、托物言志、用典抒情、 借古讽今等) 2.内容:写出…内容,描绘…的情景(画面),体现.特点 3.情感:表达了……的情感心理),或者渲染了…..的意境氛围 4.结构: 照应1与标题或者前后某内容照应),铺垫(为下文作了铺垫) 说明 1.所考的是诗歌的第一句,有时要考虑:点明时令,总领全诗,奠定情感基调 所考的是诗歌的最后一句,有时要考虑:言有尽而意无穷,给读者留下 想象空间。 2.如果该句没有什么突出手法,那么我们的精力应该花在内容、情感结构上 题型迁移 二 提问方式:某句诗有什么作用 作用题的答题模式约等于“炼句题” 说明:“炼句“与某句诗作用”的区别 “炼句”侧重于本句的手法,而“某句诗作用“则是侧重于结构与内容。 \",\"height\":1277,\"orgHeight\":1277,\"orgWidth\":1080,\"prism_version\":\"1.0.9\",\"prism_wnum\":26,\"prism_wordsInfo\":[{\"angle\":-87,\"direction\":0,\"height\":83,\"pos\":[{\"x\":177,\"y\":56},{\"x\":260,\"y\":60},{\"x\":259,\"y\":88},{\"x\":176,\"y\":84}],\"prob\":96,\"width\":28,\"word\":\"炼句\",\"x\":203,\"y\":30},{\"angle\":-87,\"direction\":0,\"height\":115,\"pos\":[{\"x\":172,\"y\":114},{\"x\":287,\"y\":120},{\"x\":286,\"y\":146},{\"x\":171,\"y\":141}],\"prob\":98,\"width\":27,\"word\":\"提问方式\",\"x\":215,\"y\":71},{\"angle\":-89,\"direction\":0,\"height\":280,\"pos\":[{\"x\":287,\"y\":119},{\"x\":567,\"y\":119},{\"x\":567,\"y\":146},{\"x\":287,\"y\":146}],\"prob\":97,\"width\":26,\"word\":\"1.请赏析诗歌某一联(句)\",\"x\":414,\"y\":-8},{\"angle\":0,\"direction\":0,\"height\":27,\"pos\":[{\"x\":286,\"y\":167},{\"x\":576,\"y\":164},{\"x\":576,\"y\":192},{\"x\":286,\"y\":194}],\"prob\":98,\"width\":289,\"word\":\"2.赏析某一联(句)的妙处\",\"x\":286,\"y\":165},{\"angle\":0,\"direction\":0,\"height\":30,\"pos\":[{\"x\":285,\"y\":213},{\"x\":667,\"y\":207},{\"x\":667,\"y\":236},{\"x\":285,\"y\":242}],\"prob\":96,\"width\":382,\"word\":\"3.请赏析诗歌某一联1句)的表达效果\",\"x\":285,\"y\":209},{\"angle\":-90,\"direction\":0,\"height\":156,\"pos\":[{\"x\":165,\"y\":284},{\"x\":321,\"y\":284},{\"x\":321,\"y\":310},{\"x\":165,\"y\":310}],\"prob\":98,\"width\":26,\"word\":\"常规答题思路\",\"x\":231,\"y\":219},{\"angle\":-2,\"direction\":0,\"height\":26,\"pos\":[{\"x\":357,\"y\":288},{\"x\":441,\"y\":286},{\"x\":442,\"y\":312},{\"x\":358,\"y\":314}],\"prob\":97,\"width\":84,\"word\":\"1.手法:\",\"x\":357,\"y\":287},{\"angle\":0,\"direction\":0,\"height\":32,\"pos\":[{\"x\":163,\"y\":332},{\"x\":958,\"y\":319},{\"x\":959,\"y\":351},{\"x\":163,\"y\":364}],\"prob\":91,\"width\":796,\"word\":\"1写景的句子侧重于写景手法(感官、角度.动静、虚实、典型画面、寓情于景等)\",\"x\":163,\"y\":324},{\"angle\":0,\"direction\":0,\"height\":30,\"pos\":[{\"x\":161,\"y\":380},{\"x\":768,\"y\":374},{\"x\":768,\"y\":404},{\"x\":162,\"y\":410}],\"prob\":96,\"width\":607,\"word\":\"②写人的句子侧重于写人手法(动作、心理、肖像、细节等)\",\"x\":161,\"y\":376},{\"angle\":0,\"direction\":0,\"height\":30,\"pos\":[{\"x\":159,\"y\":430},{\"x\":951,\"y\":417},{\"x\":951,\"y\":448},{\"x\":159,\"y\":460}],\"prob\":91,\"width\":792,\"word\":\"③抒情的句子侧重于抒情方式(直抒胸意、借景抒情、托物言志、用典抒情、\",\"x\":159,\"y\":423},{\"angle\":-89,\"direction\":0,\"height\":141,\"pos\":[{\"x\":155,\"y\":477},{\"x\":297,\"y\":479},{\"x\":296,\"y\":507},{\"x\":155,\"y\":505}],\"prob\":96,\"width\":27,\"word\":\"借古讽今等)\",\"x\":212,\"y\":420},{\"angle\":0,\"direction\":0,\"height\":31,\"pos\":[{\"x\":154,\"y\":527},{\"x\":830,\"y\":522},{\"x\":830,\"y\":553},{\"x\":154,\"y\":559}],\"prob\":97,\"width\":677,\"word\":\"2.内容:写出…内容,描绘…的情景(画面),体现.特点\",\"x\":154,\"y\":524},{\"angle\":0,\"direction\":0,\"height\":30,\"pos\":[{\"x\":150,\"y\":579},{\"x\":826,\"y\":571},{\"x\":827,\"y\":602},{\"x\":150,\"y\":610}],\"prob\":91,\"width\":677,\"word\":\"3.情感:表达了……的情感心理),或者渲染了…..的意境氛围\",\"x\":150,\"y\":575},{\"angle\":-1,\"direction\":0,\"height\":28,\"pos\":[{\"x\":148,\"y\":635},{\"x\":262,\"y\":630},{\"x\":263,\"y\":658},{\"x\":149,\"y\":663}],\"prob\":97,\"width\":115,\"word\":\"4.结构:\",\"x\":148,\"y\":631},{\"angle\":0,\"direction\":0,\"height\":29,\"pos\":[{\"x\":273,\"y\":631},{\"x\":916,\"y\":621},{\"x\":917,\"y\":651},{\"x\":274,\"y\":661}],\"prob\":96,\"width\":643,\"word\":\"照应1与标题或者前后某内容照应),铺垫(为下文作了铺垫)\",\"x\":273,\"y\":626},{\"angle\":-90,\"direction\":0,\"height\":60,\"pos\":[{\"x\":150,\"y\":712},{\"x\":210,\"y\":712},{\"x\":210,\"y\":738},{\"x\":150,\"y\":738}],\"prob\":99,\"width\":26,\"word\":\"说明\",\"x\":167,\"y\":694},{\"angle\":0,\"direction\":0,\"height\":31,\"pos\":[{\"x\":155,\"y\":764},{\"x\":988,\"y\":752},{\"x\":989,\"y\":783},{\"x\":155,\"y\":794}],\"prob\":95,\"width\":834,\"word\":\"1.所考的是诗歌的第一句,有时要考虑:点明时令,总领全诗,奠定情感基调\",\"x\":154,\"y\":757},{\"angle\":0,\"direction\":0,\"height\":31,\"pos\":[{\"x\":189,\"y\":815},{\"x\":954,\"y\":809},{\"x\":954,\"y\":840},{\"x\":189,\"y\":846}],\"prob\":98,\"width\":765,\"word\":\"所考的是诗歌的最后一句,有时要考虑:言有尽而意无穷,给读者留下\",\"x\":188,\"y\":811},{\"angle\":-89,\"direction\":0,\"height\":120,\"pos\":[{\"x\":147,\"y\":874},{\"x\":267,\"y\":874},{\"x\":267,\"y\":902},{\"x\":147,\"y\":902}],\"prob\":98,\"width\":28,\"word\":\"想象空间。\",\"x\":191,\"y\":827},{\"angle\":0,\"direction\":0,\"height\":32,\"pos\":[{\"x\":140,\"y\":957},{\"x\":1002,\"y\":950},{\"x\":1002,\"y\":983},{\"x\":140,\"y\":990}],\"prob\":96,\"width\":862,\"word\":\"2.如果该句没有什么突出手法,那么我们的精力应该花在内容、情感结构上\",\"x\":139,\"y\":953},{\"angle\":-89,\"direction\":0,\"height\":127,\"pos\":[{\"x\":133,\"y\":1043},{\"x\":260,\"y\":1045},{\"x\":260,\"y\":1076},{\"x\":133,\"y\":1074}],\"prob\":97,\"width\":31,\"word\":\"题型迁移\",\"x\":180,\"y\":995},{\"angle\":-90,\"direction\":0,\"height\":38,\"pos\":[{\"x\":5,\"y\":1109},{\"x\":44,\"y\":1109},{\"x\":44,\"y\":1150},{\"x\":5,\"y\":1150}],\"prob\":79,\"width\":40,\"word\":\"二\",\"x\":4,\"y\":1108},{\"angle\":0,\"direction\":0,\"height\":34,\"pos\":[{\"x\":130,\"y\":1103},{\"x\":468,\"y\":1098},{\"x\":469,\"y\":1131},{\"x\":130,\"y\":1136}],\"prob\":97,\"width\":339,\"word\":\"提问方式:某句诗有什么作用\",\"x\":129,\"y\":1099},{\"angle\":-89,\"direction\":0,\"height\":411,\"pos\":[{\"x\":495,\"y\":1099},{\"x\":905,\"y\":1101},{\"x\":905,\"y\":1132},{\"x\":494,\"y\":1130}],\"prob\":97,\"width\":30,\"word\":\"作用题的答题模式约等于“炼句题”\",\"x\":684,\"y\":910},{\"angle\":-1,\"direction\":0,\"height\":33,\"pos\":[{\"x\":125,\"y\":1168},{\"x\":552,\"y\":1159},{\"x\":553,\"y\":1191},{\"x\":126,\"y\":1201}],\"prob\":98,\"width\":427,\"word\":\"说明:“炼句“与某句诗作用”的区别\",\"x\":124,\"y\":1163},{\"angle\":0,\"direction\":0,\"height\":33,\"pos\":[{\"x\":131,\"y\":1226},{\"x\":897,\"y\":1221},{\"x\":898,\"y\":1255},{\"x\":132,\"y\":1260}],\"prob\":95,\"width\":766,\"word\":\"“炼句”侧重于本句的手法,而“某句诗作用“则是侧重于结构与内容。\",\"x\":130,\"y\":1224}],\"width\":1080}" }
执行代码后,会返回RequestId、Data、Code和Message四种类型的数据,如果正确返回了数据,说明陪玩平台源码图片文字识别成功,如果返回的code值不是200,说明识别错误。
声明:以上内容为云豹科技原创,未经作者本人同意,禁止转载,否则将追究相关法律责任www.yunbaokj.com