Android百度AI植物识别教程,微信开发+百度AI学习:植物识别(示例代码)
直接上代码
服务端代码如下
private static readonly Baidu.Aip.ImageClassify.ImageClassify client = new Baidu.Aip.ImageClassify.ImageClassify(ApiConfig.APIKey, ApiConfig.SecretKey);
///
/// 植物识别
///
///
public PlantModel PlantDetect(string filesrc)
{
var image = File.ReadAllBytes(filesrc);
var result = client.PlantDetect(image);
return GetPlant(result);
}
///
/// 植物识别
///
///
///
public JsonResult PlantDetect(string serverId = "")
{
string filename = System.Web.HttpContext.Current.Server.MapPath("/Static/img/demoplant.jpg");
if (!string.IsNullOrWhiteSpace(serverId))
{
filename = GetFileName(serverId);
}
var data = imageClassify.PlantDetect(filename);
return Json(data, JsonRequestBehavior.AllowGet);
}
///
/// 下载微信图片
///
/// 微信返回的图片的服务器端ID
///
private string GetFileName(string serverId)
{
string filename = System.Web.HttpContext.Current.Server.MapPath("/upload/img/");
if (!System.IO.Directory.Exists(filename))
System.IO.Directory.CreateDirectory(filename);
string date = DateTime.Now.ToString("yyyy-MM-dd");
filename += date + "/";
if (!System.IO.Directory.Exists(filename))
System.IO.Directory.CreateDirectory(filename);
string guid = Guid.NewGuid().ToString();
filename += $"/{guid}.jpg";
WeixinUtility.GetVoice(serverId, filename);
return filename;
}
前端代码如下
@{
if (ViewData["type"].ToString() == "1")
{
ViewBag.Title = "植物识别";
}else if (ViewData["type"].ToString() == "2")
{
ViewBag.Title = "动物识别";
}
else if (ViewData["type"].ToString() == "3")
{
ViewBag.Title = "车型识别";
}
Layout = "~/Views/Shared/_LayoutWeUI.cshtml";
}
名称
{{k.name}}
上传{{title}}图片
@section PageJS{
var app = new Vue({
el: "#app",
data: {
imgsrc: "",
localId: "",
serverId: "",
flag: 1,
recorder: null,
title: "",
url: "",
result:[]
},
mounted: function () {
var that = this;
var type [email protected]["type"];
if (type == 1) {
this.title = "植物";
this.imgsrc = "/Static/img/demoplant.jpg";
this.url = '@Url.Action("PlantDetect", "ImageRecognition")';
}
else if (type == 2) {
this.title = "动物";
this.imgsrc = "/Static/img/demoanimal.jpg";
this.url = '@Url.Action("AnimalDetect", "ImageRecognition")';
}
else if (type == 3) {
this.title = "车型";
this.imgsrc = "/Static/img/democar.jpg";
this.url = '@Url.Action("CarDetect", "ImageRecognition")';
}
this.detect();
},
methods: {
detect() {
var that = this;
$.sunloading.show("正在识别");
$.ajax({
url: this.url,
dataType: "json",
type: "post",
data: { serverId: this.serverId },
success: function (result) {
$.sunloading.close();
console.log("识别结果:" + result);
that.result = result.result;
},
error: function (e) {
console.log(e);
}
});
},
getscore(score) {
return (score * 100).toFixed(2) + "%";
},
uploader() {
var that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
console.log(res.localIds);
that.localId = res.localIds[0]; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
that.uploadImage();
}
});
},
uploadImage() {
var that = this;
wx.uploadImage({
localId: that.localId, // 需要上传的图片的本地ID,由chooseImage接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function (res) {
that.serverId = res.serverId; // 返回图片的服务器端ID
that.detect();
}
});
}
}
});
}
运行效果如下
Android百度AI植物识别教程,微信开发+百度AI学习:植物识别(示例代码)相关推荐
- 视频教程-微信公众号使用教程-微信开发
微信公众号使用教程 大秦电商创始人,专注网络技术的电商应用.已经出品<1小时建站><微博营销实战><PHP采集><网络招商系统> 秦子恒 ¥39.00 ...
- 视频教程-微信小程序开发培训教程-微信开发
微信小程序开发培训教程 本人计算机专业,毕业工作已经10多年,从事过的行业有,安防,通讯,Gps定位,信息统计分析,互联网电商等,从事过的职位. 代码工程师(使用过的语言C#,PHP,Java),Ap ...
- 视频教程-基于python的微信公众号开发教程-微信开发
基于python的微信公众号开发教程 微信企业号星级会员.10多年软件从业经历,国家级软件项目负责人,主要从事软件研发.软件企业员工技能培训.已经取得计算机技术与软件资格考试(软考)--"信 ...
- android仿微信语音聊天功能,Android仿微信发送语音消息的功能及示例代码
微信的发送语音是有一个向上取消的,我们使用ontouchlistener来监听手势,然后做出相应的操作就行了. 直接上代码: //语音操作对象 private mediaplayer mplayer ...
- 微信小程序 获取手机号 JavaScript解密示例代码详解
刚开始开发微信小程序的时候,想着实现手机验证码登入,后来查阅资料得知,发给用户的短信是要自己付费的.后来想想,微信获取用户的手机号一样可以保证手机号码的真实性,因为手机号既然可以绑定微信,那么肯定是被 ...
- 开发人员必备:微软发布示例代码浏览器 (Sample Browser) 第五版,让您尽享3500个示例代码...
今天早上,微软一站式示例代码库 携手MSDN和微软创新空间 正式发布了示例代码浏览器(Sample Browser)第五版.这是继去年10月第四版发布以来的一次重大升级.有了它,3500多高质量示例代 ...
- 【百度智能云】教程:连接百度ai开放平台api接口并完成语音识别的任务
前言与介绍 本文章介绍了如何在Pycharm上用python语言简单的对连接百度ai开放平台的语音识别功能api端口的调用,并在代码里实现了现录音识别内容. 平台与相关工具 windows10.Pyc ...
- SuperMap iMobile+Android studio开发入门(二)——超图示例代码运行
背景:这里运行的是"产品入门"的"基于Android studio开发移动GIS程序"的"开发三维移动GIS程序",本篇对超图帮助文档进行了 ...
- php公众号客服消息图文,微信公众号开发系列-发送客服消息(示例代码)
下面是做微信公众号开发用到最多的两个客服消息发送类型,文本信息和图文信息. 1.发送文本消息{ "touser":"OPENID", "msgtype ...
最新文章
- CxImage图像处理类库
- 博客网站源代码_网站建设技术--WORDPRESS
- Android开发中高效的数据结构用SparseArray代替HashMap
- gem ransack(4000✨) 简单介绍
- 面试官:大型系统架构设计细节你知道多少??
- mysql时间排序最后一个_如何在MySQL中按日期排序,但最后放置空日期?
- maven 集成 CXF
- Web Server监视器 v0.75 - Free tool
- python程序设计课后答案第二版_智慧职教APPPython程序设计(深圳信息职业技术学院)课后答案...
- Kalman Filter—Data Fusion, Covarince Matrix, State Space Representation, Observation
- oracle19c ojdbc6,解决ojdbc6升级ojdbc8中文乱码问题
- linux脚本取消空格,Shell去除空格和空行的方法
- 软件测试入门理论基础
- HTML+CSS项目实践五:使用纯CSS实现点击文字切换图片效果(不使用JS)
- [项目分享]JSP+Servlet+JDBC实现的shine网上书城
- 网站点击量太大崩溃怎么办_网站崩溃时该怎么办
- Confusing conditions about MySQL script
- 类别,非正式协议,正式协议
- 【TensorFlow】神经网络中间层截取、可视化中间层结果
- 论文阅读:2010-基于随机加工时间和模糊交货期的加工车间调度问题