├── LICENSE ├── README.md ├── app.js ├── app.json ├── app.wxss ├── config.js ├── example ├── demo.jpeg ├── model.jpg └── qrcode.jpg ├── img ├── quote.png └── upload.jpg ├── pages └── index │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss └── project.config.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 深知人工智能 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 深度识图 2 | 3 | 深度识图是基于 [gotalk](https://github.com/agilab/gotalk) 作为后端识别引擎的前端小程序,使用了 Google 的深度学习图片识别技术,可以将一张图片转化为一句话描述。 4 | 5 | ![](./example/model.jpg) 6 | 7 | 这个小程序能识别大部分人物场景,也可以直接从头像识别头像内容。 8 | 9 | ## 在线体验 10 | 11 | 微信扫一扫小程序码 12 | 13 | ![](./example/qrcode.jpg) 14 | 15 | 页面这样的 16 | 17 | ![](./example/demo.jpeg) 18 | 19 | ## 快速上手 20 | 21 | **后端** 22 | 23 | [gotalk](https://github.com/agilab/gotalk) 提供了后端的基本接口,以及图片识别算法。 24 | 25 | 此外还需要一个 [服务接口](https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html) 处理小程序的图片上传并返回图片地址,请开发者自行解决。 26 | 27 | **前端** 28 | 29 | 首先在 **project.config.json** 添加自己的 appid 30 | 31 | 在 **config.js** 中添加自己的后端服务地址 32 | 33 | ```js 34 | 35 | export default { 36 | ServerUrl: '', // 在这里修改ServerUrl,也就是gotalk的地址 37 | uploadServerUrl: '' // 小程序图片上传的地址 38 | } 39 | 40 | ``` 41 | 42 | 之后用微信开发者工具打开,快速使用。 43 | 44 | ## 其他 45 | 46 | 目前不支持除 jpg 格式以外的图片, 有条件可用 OSS 带参数链接自行解决。 47 | 48 | 更多问题欢迎加入我们的 QQ 群 850275221。 49 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | App({}) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages":[ 3 | "pages/index/index" 4 | ], 5 | "window":{ 6 | "backgroundTextStyle":"light", 7 | "navigationBarBackgroundColor": "#fff", 8 | "navigationBarTitleText": "WeChat", 9 | "navigationBarTextStyle":"black" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | page { 3 | background: #F5F5F5; 4 | } 5 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | 2 | export default { 3 | ServerUrl: '', // 在这里修改ServerUrl,也就是gotalk的地址 4 | uploadServerUrl: '' // 小程序图片上传的地址 5 | } -------------------------------------------------------------------------------- /example/demo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agilab/mini_app_ai/d660911dc9f8e8e57456ca170f9b067ec76772a1/example/demo.jpeg -------------------------------------------------------------------------------- /example/model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agilab/mini_app_ai/d660911dc9f8e8e57456ca170f9b067ec76772a1/example/model.jpg -------------------------------------------------------------------------------- /example/qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agilab/mini_app_ai/d660911dc9f8e8e57456ca170f9b067ec76772a1/example/qrcode.jpg -------------------------------------------------------------------------------- /img/quote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agilab/mini_app_ai/d660911dc9f8e8e57456ca170f9b067ec76772a1/img/quote.png -------------------------------------------------------------------------------- /img/upload.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agilab/mini_app_ai/d660911dc9f8e8e57456ca170f9b067ec76772a1/img/upload.jpg -------------------------------------------------------------------------------- /pages/index/index.js: -------------------------------------------------------------------------------- 1 | //index.js 2 | //获取应用实例 3 | import config from '../../config' 4 | 5 | Page({ 6 | data: { 7 | detail: '识别中..', 8 | url: '' 9 | }, 10 | onLoad({ picurl, detail }) { 11 | wx.setNavigationBarTitle({ 12 | title: 'AI深度识图', 13 | }) 14 | if (picurl) { 15 | this.setData({ 16 | url: picurl, 17 | detail 18 | }, () => { 19 | this.sendImg(this.data.url) 20 | }) 21 | } 22 | }, 23 | onUploadAvatar() { 24 | let that = this; 25 | wx.showLoading({ 26 | title: '处理中', 27 | }) 28 | wx.getUserInfo({ 29 | success(weChatInfo) { 30 | let url = weChatInfo.userInfo.avatarUrl.slice(0, -3) + '0' // 转化成高清图 31 | that.sendImg(url) 32 | }, 33 | fail() { 34 | wx.showToast({ 35 | title: '授权失败, ai无法从头像识别', 36 | icon: 'none' 37 | }) 38 | } 39 | }) 40 | }, 41 | onUploadPic(e) { 42 | let that = this; 43 | wx.chooseImage({ 44 | count: 1, 45 | sizeType: ['compressed'], 46 | success(res) { 47 | wx.showLoading({ 48 | title: '处理中', 49 | }) 50 | that.upoloadFile(res.tempFilePaths[0]) 51 | } 52 | }) 53 | }, 54 | upoloadFile(pic) { 55 | let that = this 56 | wx.uploadFile({ 57 | url: config.uploadServerUrl, 58 | filePath: pic, 59 | name: 'File', 60 | success(res) { 61 | /** 62 | * 从服务器拿到上传后图片的地址 63 | */ 64 | that.setData({ url:res.data.url }, () => { 65 | that.sendImg(that.data.url) 66 | }) 67 | }, 68 | fail() { 69 | wx.showToast({ 70 | title: '上传失败', 71 | icon: 'fail', 72 | }) 73 | } 74 | }) 75 | }, 76 | sendImg(url) { 77 | let that = this; 78 | wx.request({ 79 | method: 'get', 80 | url: config.ServerUrl, 81 | success(res) { 82 | if (res.data.error) { 83 | wx.showToast({ 84 | title: '图片当前仅支持jpg格式', 85 | icon: 'none' 86 | }) 87 | wx.hideLoading() 88 | return 89 | } else { 90 | /** 91 | * 在gotalk的结果中选择概率最大的 92 | */ 93 | res.data.results.sort((a, b) => { 94 | if (a.probability > b.probability) return -1 95 | else return 1 96 | }) 97 | that.setData({ 98 | detail: res.data.results[0].sentence, 99 | url, 100 | }, () => { 101 | wx.hideLoading() 102 | }) 103 | } 104 | } 105 | }) 106 | }, 107 | onShareAppMessage() { 108 | if(this.data.oss_key) { 109 | return { 110 | title: 'AI智能识图来了,快来看看我的识别结果', 111 | path: '/pages/index/index?url=' + this.data.url + '&detail=' + this.data.detail 112 | } 113 | } else { 114 | return { 115 | title: 'AI智能识图来了,从此告别脸盲' 116 | } 117 | } 118 | } 119 | }) 120 | -------------------------------------------------------------------------------- /pages/index/index.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | {{ detail }} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 杭州深知科技 数据智能部 23 | 24 | 25 | -------------------------------------------------------------------------------- /pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | .card { 2 | background: #fff; 3 | border-radius: 10rpx; 4 | padding: 20rpx; 5 | } 6 | .container { 7 | margin: auto; 8 | width: 710rpx; 9 | } 10 | .upload { 11 | margin-top: 20rpx; 12 | } 13 | .inner-wrap { 14 | background: #FFFFFF; 15 | border: 2rpx dashed #C2C4CA; 16 | border-radius: 6rpx; 17 | height: 550rpx; 18 | text-align: center; 19 | } 20 | .uplaod-btn { 21 | margin-top: 30rpx; 22 | background: #FF7F71; 23 | border: 1px solid rgba(5,5,5,0.08); 24 | border-radius: 10rpx; 25 | color: white 26 | } 27 | .btn { 28 | margin-top: 30rpx; 29 | font-size: 34rpx; 30 | color: #333333; 31 | } 32 | .concat-btn { 33 | padding: 0; 34 | font-size: 26rpx; 35 | color: #576B95; 36 | display: inline-block; 37 | } 38 | .concat-btn::after{ border: none; } 39 | .inner-wrap image { 40 | margin-top: 140rpx; 41 | width: 220rpx; 42 | } 43 | .picture { 44 | margin-top: 20rpx; 45 | } 46 | .picture .origin-pic { 47 | width: 100%; 48 | height: 500rpx; 49 | } 50 | .picture .quotes { 51 | width: 40rpx; 52 | margin-right: 20rpx; 53 | } 54 | .picture .reson { 55 | margin-top: 12rpx; 56 | } 57 | .picture .reson-text { 58 | font-size: 34rpx; 59 | color: #4A4A4A; 60 | } 61 | .footer { 62 | font-size: 24rpx; 63 | color: #999999; 64 | position: absolute; 65 | bottom: 12rpx; 66 | left: 0; right: 0; 67 | text-align: center; 68 | } -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "packOptions": { 4 | "ignore": [] 5 | }, 6 | "setting": { 7 | "urlCheck": false, 8 | "es6": true, 9 | "postcss": true, 10 | "minified": true, 11 | "newFeature": true 12 | }, 13 | "compileType": "miniprogram", 14 | "libVersion": "2.2.5", 15 | "appid": "", 16 | "projectname": "img2text", 17 | "isGameTourist": false, 18 | "condition": { 19 | "search": { 20 | "current": -1, 21 | "list": [] 22 | }, 23 | "conversation": { 24 | "current": -1, 25 | "list": [] 26 | }, 27 | "game": { 28 | "currentL": -1, 29 | "list": [] 30 | }, 31 | "miniprogram": { 32 | "current": -1, 33 | "list": [] 34 | } 35 | } 36 | } --------------------------------------------------------------------------------