OpenResy+Lua 利用百度识图 将图片地址解析成文字
LUA代码:(注:LUA里有一个调用百度识图的接口IP:123.125.115.189(stu.baidu.com),不知为什么我的虚拟机无法解析stu.baidu.com,所以我只能PING出IP来用。)
location /test {
content_by_lua '
local request_method = ngx.var.request_method;
local args = nil;
if "GET" == request_method then
args = ngx.req.get_uri_args();
else
ngx.req.read_body();
args = ngx.req.get_post_args();
end
local imageUrl = args["imageUrl"]
function Split(szFullString, szSeparator)
local nFindStartIndex =
local nSplitIndex =
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - )
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex +
end
return nSplitArray
end
local cjson = require "cjson"
local http = require "resty.http"
local hc = http:new()
local ok, code, headers, status, body = hc:request {
url = "http://123.125.115.189/n/pc_search?queryImageUrl="..imageUrl,
method = "GET", -- POST or GET
}
local _,aaa = string.find(body,"keywords:\'")
local bbb = string.find(body,"|default")
local ccc = string.sub(body,aaa+,bbb-)
ngx.say(tostring(ccc))
';
}
HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled</title>
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
</head> <body> <input type="button" value = "test" id ="test" />
<input type="text" id ="imgUrl" />
<input type="button" value = "识图" id ="st" /> </body> <script> function unicode2Chr(str) {
str=str.replace(/\\/g,"%");
return unescape(str); } $(function(){
$("#test").click(function(){
alert();
var str = "\x22\\u82f9\\u679c\x22,\x22\\u6307\\u6325\\u5927\\u5e08\x22,\x22\\u51fa\\u67dc\x22";
var code = str.replace(/\x22/g, "")
alert(code);
alert(unicode2Chr(code));
}); $("#st").click(function(){ var image_Url = $("#imgUrl").val(); $.ajax({
type : "POSST",
async : false,
url : "/test",
data:{imageUrl:image_Url},
success : function(data) {
var code = data.replace(/\\x22/g, "")
alert(unicode2Chr(code).replace(/%/g, ""));
}
});
}); }); </script>
</html>
OpenResy+Lua 利用百度识图 将图片地址解析成文字的更多相关文章
- 安卓开发 利用百度识图api进行物体识别
前文 之前的随笔中,已经通过相机或相册获取到了我们想要的图片,接下来进行识图api的配置工作.我使用的是百度的api,利用python获取信息,并在MainActivity中进行调用来输出信息. 一. ...
- 安卓开发 利用百度识图api进行物体识别(java版)
之前的随笔中,已经实现了python版本调用api接口,之所以使用python是因为python比java要简洁. 但是我发现在使用过程中,chaquopy插件会弹出底部toast显示"un ...
- 利用百度AI OCR图片识别,Java实现PDF中的图片转换成文字
序言:我们在读一些PDF版书籍的时候,如果PDF中不是图片,做起读书笔记的还好:如果PDF中的是图片的话,根本无法编辑,做起笔记来,还是很痛苦的.我是遇到过了.我们搞技术的,当然得自己学着解决现在的痛 ...
- 通过AI识图判断图片是否为小票
先在百度智能云中创建一个应用加入以下标记功能(没有智能云账号可以去创建一个,创建应用也都是些基本操作) 本次只用到标记的功能. 此功能在图像识别下面. 创建应用后,页面会出现平台分配的密钥:API K ...
- 百度识图for windows phone 上线
原文发布时间为:2013-07-04 -- 来源于本人的百度文章 [由搬家工具导入] 百度识图主要用于找女神,找男神,找美图,找宠物,找图文新闻,找相似图,找原图,还能鉴别头像照片真伪,免得被网络照片 ...
- 百度识图API
http://stu.baidu.com/ http://www.360doc.com/content/14/0801/17/21412_398653199.shtml http://download ...
- 阿里云OCR图片转换成文字识别调用
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; using S ...
- PHP图片识别成文字
http://apistore.baidu.com/apiworks/servicedetail/146.html 分类: php2011-- : 3576人阅读 评论() 收藏 举报 phpfunc ...
- python3 自动识图
一.安装依赖库 pip install pytesseract pip install pillow 二.安装识图引擎tesseract-ocr https://pan.baidu.com/s/1Qa ...
随机推荐
- ios 拨打电话
1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示NSMutableString * str=[[NSMutableString alloc] initWithFo ...
- 在帝都的Android面试感想
#第一次面试赤子城Android开发实习生 关于面试的表现和感想 1.没有准备充分就去面试(这是大忌,也就直接决定了结果) 我去面试Android,但是却不知道很多关于Android的基础知识,就是明 ...
- Delphi中的异常处理
转载:http://www.cnblogs.com/doit8791/archive/2012/05/08/2489471.html 以前写Delphi程序一直不注意异常处理,对其异常处理的机制总是一 ...
- 【翻译二十一】java-并发之分拆和合并
Fork/Join This section was updated to reflect features and conventions of the upcoming Java SE 8 rel ...
- float 的有效数字为七位是怎么得出来的
以下内容来自CSDN网友xian_wwq的回答(http://bbs.csdn.net/topics/390874239): float: 1bit(符号位) 8bits(指数位) 23bits( ...
- Oracle备份 还原命令
1.备份命令 exp username/password file=d:/test/test.dmp; 2.还原命令 imp username/password full=y file=d:/test ...
- IOS 100 - level2 Boss
创建第一个app, buid, run. 过程 1 首先是按照知乎上的推荐去看了传说中的公开课了.看到第二集的时候觉得有种回到大学听老师上课的感觉--昏昏欲睡. 代码是一门实践课程,我觉得自己实现点东 ...
- 六款值得推荐的android(安卓)开源框架简介(转)
1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1) JSON,图像等的异步下载: (2) 网络请求的排序(scheduli ...
- AndroidStudio中创建Assets文件
- 【JDBC 报错】Connections could not be acquired from the underlying database!
项目启动报错: [2016-07-13 10:04:15,074] ERROR org.apache.ibatis.executor.BaseExecutor Could not get a data ...