[Perl]腾讯云 生成签名、图片识别接口调用实例

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

[Perl]腾讯云 生成签名、图片识别接口调用实例

帖子 523066680 »

腾讯的官方文档:https://cloud.tencent.com/document/product/866/17734
官方的签名生成示例分别是 PHP JAVA Nodejs 和 C++ 的,所以我改了一个Perl的版本,补充了提交识别网络图片的代码。
appid 和 secret_id , secret_key 我去除了,测试时请自行申请腾讯云账户后填入
=info 腾讯云 印刷体图片识别示例 523066680/vicyang 2018-12 =cut use LWP::UserAgent; use Encode; use utf8; use MIME::Base64; use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex); STDOUT->autoflush(1); my $s = sign(); my $ua = LWP::UserAgent->new(); my $json = '{"appid":"1254154701", "url":"http://www.code-by.org/styles/prosilver ... e_logo.png"}'; my @header = ( 'Authorization' => $s, 'Host' => 'recognition.image.myqcloud.com', 'Content-Type' => 'application/json', ); #$ua->default_header( @header ); my $res = $ua->post( 'http://recognition.image.myqcloud.com/ocr/general', @header, 'Content' => $json, ); print encode('gbk', decode('utf8', $res->content())); sub sign { my $appid = "APPID"; my $secret_id = "Secret_id"; my $secret_key = "Secret_key"; my $current = time(); my $rdm = int( rand(10000) + 10000 ); my $userid = 0; my @list = ( [ 'a' => $appid ], [ 'k' => $secret_id ], [ 'e' => $current + 100 ], [ 't' => $current ], [ 'r' => $rdm ], [ 'u' => $userid ], [ 'f' => '' ], ); $srcStr = join("", map { $_->[0] ."=". $_->[1] ."&" } @list ); $srcStr =~s/&$//; # 生成签名,最右双引号表示不换行 my $signStr = encode_base64( hmac_sha1( $srcStr, $secret_key) .$srcStr, "" ); printf "%s\n", $srcStr; return $signStr; }
输出:

代码: 全选

{"code":0,"message":"OK","data":{"class":[],"angle":0.0,"items":[{"itemcoord":{"x":7,"y":20,"width":135,"height":13},"words":[{"character":"P","confidence":0.8444133400917053},{"character":"","confidence":1.0},{"character":"r","confidence":0.6299126744270325},{"character":"o","confidence":0.9383134841918944},{"character":"g","confidence":0.945770502090454},{"character":"r","confidence":0.9737642407417296},{"character":"","confidence":1.0},{"character":"a","confidence":0.9953640699386596},{"character":"","confidence":1.0},{"character":"m","confidence":0.9897430539131165},{"character":"m","confidence":0.9669923186302184},{"character":"i","confidence":0.9982288479804992},{"character":"n","confidence":0.999599277973175},{"character":"g","confidence":0.9985522627830504}],"itemstring":"P rogr a mming"}],"session_id":""}}
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

[腾讯云-图片识别]某扫描版电子书样张,识别测试

帖子 523066680 »

某个扫描版电子书样张
[image 400,500]http://img.gzsophy.com/test/BookSample.png[/image]
扫描结果
22
第1章
1.设置好工具集所要求的环境变量。
2.输入一个 命令,告诉编译器编译和链接程序。
用于设置环境变量的脚本程序如表1-5所示。这些脚本程序位于命令行工具的相同目录中
(见表1-3所示)。如果你所用的工具集没有出现在表1-5中,那么你就可以跳过第1步。
否则,如果你使用的是Windows系统,则运行相应的脚本程序;如果使用的是Unix系
统,则编写相应的脚本程序。
表1-5命令行工具需要的用于设置环境变量的脚本
工具集
脚本
Visual C++
vcvars32. bat
Intel (Windows)
iclvars. bat
Intel (Linux)
iccvars.sh或iccvars. csh
Metrowerks (Mac OS X)
mwvars.sh或mwvars. csh
Metrowerks (Windows)
cwenv. bat
Comeau
与后端的工具集相同
编译和链接hello.cpp的命令如表1-6所示。要使这些命令正确运行,应使当前目录是含
有hello.cpp的目录,且包含命令行编译器的目录应出现在PATH环境变量中。如果已在
第1步中运行了脚本程序,那么后面的条件将自动满足。也有可能在你安装工具集时,安
装程序就把包含命令行工具的目录添加到PATH中了。如果不是这样,你就得如表1-7所
示的那样把目录添加到PATH中,或在命令行中指定完整的路径名。
表1-6只用一步就可完成hello.cpp编译和链接的命令
工具集
命令行
GCC
g++ -0 hello hello.cpp
Visual C++
cl -nologo -EHsc -GR -Zc:forScope -Zc:wchar_ _t -Fehello hello. cpp
Intel (Windows)
icl -nologo -EHsc -GR -Zc:forScope -Zc:wchar_ _I -Fehello hello.cpp
Intel (Linux)
icpc -0 hello hello. cpp
Metrowerks
mwcc -wchar_ _I on -cwd include -0 hello hello.cpp
Comeau
como -0 hello hello. cpp
Borland
bcc32 -q -ehello hello.cpp
Digital Mars
dmc -Ae -Ar -I<dmcroot>/stlport/stlport -o hello hello.cpp
http://www.TopSage.com
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 4 访客