<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PlantDetection.aspx.cs" Inherits="PlantDetection" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>植物检测</title>
<link rel="stylesheet" type="text/css" href="/style/main.css" />
<link rel="stylesheet" type="text/css" href="/style/index.css" />
</head>
<body runat="server">
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<div class="header-page">
<div class="inner">
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="logo"><img src="../img/face-logo.png" alt="Face Detection" /></asp:HyperLink>
<div class="nav">
<div class="nav-li">
<ul>
<li>
<asp:HyperLink ID="plant" runat="server" NavigateUrl="/PlantDetection.aspx">植物检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="detection" runat="server" NavigateUrl="/FaceDetection.aspx">人脸检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="match" runat="server" NavigateUrl="/FaceMatch.aspx">人脸对比</asp:HyperLink></li>
<li>
<asp:HyperLink ID="contact" runat="server" NavigateUrl="/Contact.aspx">联系</asp:HyperLink></li>
<li>
<asp:HyperLink ID="about" runat="server" NavigateUrl="/About.aspx">关于</asp:HyperLink></li>
<li>
<asp:HyperLink ID="login" runat="server" NavigateUrl="/Account/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="register" runat="server" NavigateUrl="/Account/Register.aspx">注册</asp:HyperLink></li>
</ul>
</div>
</div>
</div>
</div>
<div style="text-align: center;">
<h1>功能演示</h1>
<p>即刻体验植物检测。请上传一张本地图片或提供图片URL。</p>
<p>该功能演示基于Baidu Detect API搭建</p>
</div>
<form id="form1" runat="server" style="text-align: center">
<div style="float: left; margin-top: 56px; margin-left: 300px;">
<br />
<asp:Image runat="server" ID="showPic" Style="z-index: 102; left: 20px; position: center; top: 49px;" Width="377px" Height="335px" />
<br />
<br />
<asp:FileUpload ID="picFile" runat="server" Width="152px" Style="visibility: hidden;"/>
<input type="text" readonly="readonly" id="represent" class="inputtext"/>
<input type="button" value="上传图片" id="up" style="margin-bottom: 0px" class="btn" />
<asp:Button ID="submit" runat="server" Text="识别" Width="100px" CssClass="btn" Style="margin-bottom: 0px" OnClick="submit_Click" />
</div>
<div style="float: right; margin-top: 56px; margin-right: 300px;">
<div>
<asp:Label ID="tip" runat="server" Text="▼植物属性分析"></asp:Label>
</div>
<asp:TextBox ID="plantAttribute" οnmοuseοver="this.style.borderColor='beige';this.style.backgroundColor='#CCCCCC'" ReadOnly="true" TextMode="MultiLine" runat="server" Height="332px" Style="background-color:#53868B;margin-top: 0px; font-family: 微软雅黑; font-size: 20px; font-weight: bold;" Width="376px"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="netUrl" runat="server" CssClass="inputtext"></asp:TextBox>
<asp:Button ID="netSubmit" runat="server" Text="识别网络图片" Width="116px" Onclick="netSubmit_Click" CssClass="btn" />
</div>
<br />
<br />
</form>
<div>
<asp:Literal runat="server" ID="messge" Text=""></asp:Literal>
<br />
</div>
<script src="/JS/jquery-3.2.1.min.js" charset="utf-8"></script>
<script src="/JS/process.js" charset="utf-8"></script>
</body>
</html>
public partial class PlantDetection : System.Web.UI.Page
{
string scrpit = "<script language='javascript'> {0} </script>";
protected void Page_Load(object sender, EventArgs e)
{
this.showPic.ImageUrl = "/img/demo-plant.jpg";
}
protected void submit_Click(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpResponse response = context.Response;
if (!this.picFile.HasFile)
{
//response.Write(string.Format(scrpit, "alert(\"上传文件不能为空!\");"));
this.messge.Text = string.Format(scrpit, "alert(\"上传文件不能为空!\");");
return;
}
bool fileIsValid = false;
//如果确认了上传文件,则判断文件类型是否符合要求
if (this.picFile.HasFile)
{
//获取上传文件的后缀
String fileExtension = System.IO.Path.GetExtension(this.picFile.FileName).ToLower();
String[] restrictExtension = { ".jpg", ".png" };
//判断文件类型是否符合要求
for (int i = 0; i < restrictExtension.Length; i++)
{
if (fileExtension == restrictExtension[i])
{
fileIsValid = true;
}
//如果文件类型符合要求,调用SaveAs方法实现上传,并显示相关信息
if (fileIsValid == true)
{
//上传文件是否大于10M
if (picFile.PostedFile.ContentLength > (4 * 1024 * 1024))
{
this.messge.Text = string.Format(scrpit, "alert(\"上传单个图片不能超过4MB!\");");
return;
}
try
{
this.picFile.SaveAs(Server.MapPath("~/File/") + picFile.FileName);
this.showPic.ImageUrl = "~/File/" + picFile.FileName;
}
catch
{
this.messge.Text = string.Format(scrpit, "alert(\"文件上传失败!\");");
}
finally
{
}
}
else
{
this.messge.Text = string.Format(scrpit, "alert(\"只能够上传后缀为.jpg,.png的文件!\");");
}
}
}
string result = new PlantDetect().detectPlant(Server.MapPath("~/File/") + picFile.FileName);
this.plantAttribute.Text = result;
}
protected void netSubmit_Click(object sender, EventArgs e)
{
string url = netUrl.Text.Trim();
this.showPic.ImageUrl = url;
string json = new PlantDetect().detectPlantFromNet(url);
this.plantAttribute.Text = json;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FaceDetection.aspx.cs" Inherits="FaceDetection" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人脸检测</title>
<link rel="stylesheet" type="text/css" href="/style/main.css" />
<link rel="stylesheet" type="text/css" href="/style/index.css" />
</head>
<body runat="server">
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<div class="header-page">
<div class="inner">
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="logo"><img src="../img/face-logo.png" alt="Face Detection" /></asp:HyperLink>
<div class="nav">
<div class="nav-li">
<ul>
<li>
<asp:HyperLink ID="plant" runat="server" NavigateUrl="/PlantDetection.aspx">植物检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="detection" runat="server" NavigateUrl="/FaceDetection.aspx">人脸检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="match" runat="server" NavigateUrl="/FaceMatch.aspx">人脸对比</asp:HyperLink></li>
<li>
<asp:HyperLink ID="contact" runat="server" NavigateUrl="/Contact.aspx">联系</asp:HyperLink></li>
<li>
<asp:HyperLink ID="about" runat="server" NavigateUrl="/About.aspx">关于</asp:HyperLink></li>
<li>
<asp:HyperLink ID="login" runat="server" NavigateUrl="/Account/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="register" runat="server" NavigateUrl="/Account/Register.aspx">注册</asp:HyperLink></li>
</ul>
</div>
</div>
</div>
</div>
<div style="text-align: center;">
<h1>功能演示</h1>
<p>即刻体验人脸检测。请上传一张本地图片或提供图片URL。</p>
<p>该功能演示基于Baidu Detect API搭建</p>
</div>
<form id="form1" runat="server" style="text-align: center">
<div style="float: left; margin-top: 56px; margin-left: 300px;display:inline;">
<br />
<asp:Image runat="server" ID="showPic" Style="z-index: 102; left: 20px; position: center; top: 49px;" Width="377px" Height="335px" />
<br />
<br />
<asp:FileUpload ID="picFile" runat="server" Width="152px" Style="visibility: hidden;"/>
<input type="text" readonly="readonly" id="represent" class="inputtext"/>
<input type="button" value="上传图片" id="up" style="margin-bottom: 0px" class="btn" />
<asp:Button ID="submit" runat="server" Text="检测" Width="100px" CssClass="btn" Style="margin-bottom: 0px" OnClick="submit_Click" />
</div>
<div style="float: right; margin-top: 56px; margin-right: 300px; display:inline;">
<div>
<asp:Label ID="tip" runat="server" Text="▼人脸属性分析"></asp:Label>
</div>
<asp:TextBox ID="faceAttribute" οnmοuseοver="this.style.borderColor='beige';this.style.backgroundColor='#CCCCCC'" ReadOnly="true" TextMode="MultiLine" runat="server" Height="332px" Style="background-color: #53868B; margin-top: 0px; font-family: 微软雅黑; font-size: 20px; font-weight: bold;" Width="376px"></asp:TextBox>
<br />
<br />
<asp:Button ID="netSubmit" runat="server" Text="检测网络图片" Width="116px" OnClick="netSubmit_Click" CssClass="btn" />
<asp:TextBox ID="netUrl" runat="server" CssClass="inputtext"></asp:TextBox>
</div>
<br />
<br />
</form>
<div>
<asp:Literal runat="server" ID="messge" Text=""></asp:Literal>
<br />
</div>
<script src="/JS/jquery-3.2.1.min.js" charset="utf-8"></script>
<script src="/JS/process.js" charset="utf-8"></script>
</body>
</html>
public partial class FaceDetection : System.Web.UI.Page
{
string scrpit = "<script language='javascript'> {0} </script>";
protected void Page_Load(object sender, EventArgs e)
{
this.showPic.ImageUrl = "~/img/" + "timg.jpg";
}
protected void submit_Click(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpResponse response = context.Response;
if (picFile.FileName == "")
{
//response.Write(string.Format(scrpit, "alert(\"上传文件不能为空!\");"));
this.messge.Text = string.Format(scrpit, "alert(\"上传文件不能为空!\");");
return;
}
bool fileIsValid = false;
//如果确认了上传文件,则判断文件类型是否符合要求
if (this.picFile.HasFile)
{
//获取上传文件的后缀
String fileExtension = System.IO.Path.GetExtension(this.picFile.FileName).ToLower();
String[] restrictExtension = {".jpg", ".png" };
//判断文件类型是否符合要求
for (int i = 0; i < restrictExtension.Length; i++)
{
if (fileExtension == restrictExtension[i])
{
fileIsValid = true;
}
//如果文件类型符合要求,调用SaveAs方法实现上传,并显示相关信息
if (fileIsValid == true)
{
//上传文件是否大于10M
if (picFile.PostedFile.ContentLength > (10 * 1024 * 1024))
{
this.messge.Text = string.Format(scrpit, "alert(\"上传单个图片不能超过10MB!\");");
return;
}
try
{
this.picFile.SaveAs(Server.MapPath("~/File/") + picFile.FileName);
this.showPic.ImageUrl = "~/File/" + picFile.FileName;
}
catch
{
this.messge.Text = string.Format(scrpit, "alert(\"文件上传失败!\");");
}
finally
{
}
}
else
{
this.messge.Text = string.Format(scrpit, "alert(\"只能够上传后缀为.jpg,.png的文件!\");");
}
}
}
string json = new FaceDetet().DetectFaceFromLocal(Server.MapPath("~/File/") + picFile.FileName);
//this.faceAttribute.Text = json;
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
JavaScriptSerializer Serializer = new JavaScriptSerializer();
Root obj = Serializer.Deserialize<Root>(json);
this.faceAttribute.Text = new FaceDetet().RootAnalyse(obj);
}
protected void netSubmit_Click(object sender, EventArgs e)
{
string url = netUrl.Text.Trim();
this.showPic.ImageUrl = url;
string json = new FaceDetet().DetectFaceFromNet(url);
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
JavaScriptSerializer Serializer = new JavaScriptSerializer();
Root obj = Serializer.Deserialize<Root>(json);
this.faceAttribute.Text = new FaceDetet().RootAnalyse(obj);
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FaceMatch.aspx.cs" Inherits="FaceMatch" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人脸对比</title>
<link rel="stylesheet" type="text/css" href="/style/main.css" />
<link rel="stylesheet" type="text/css" href="/style/index.css" />
</head>
<body runat="server">
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<div class="header-page">
<div class="inner">
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="logo"><img src="../img/face-logo.png" alt="Face Detection" /></asp:HyperLink>
<div class="nav">
<div class="nav-li">
<ul>
<li>
<asp:HyperLink ID="plant" runat="server" NavigateUrl="/PlantDetection.aspx">植物检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="detection" runat="server" NavigateUrl="/FaceDetection.aspx">人脸检测</asp:HyperLink></li>
<li>
<asp:HyperLink ID="match" runat="server" NavigateUrl="/FaceMatch.aspx">人脸对比</asp:HyperLink></li>
<li>
<asp:HyperLink ID="contact" runat="server" NavigateUrl="/Contact.aspx">联系</asp:HyperLink></li>
<li>
<asp:HyperLink ID="about" runat="server" NavigateUrl="/About.aspx">关于</asp:HyperLink></li>
<li>
<asp:HyperLink ID="login" runat="server" NavigateUrl="/Account/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="register" runat="server" NavigateUrl="/Account/Register.aspx">注册</asp:HyperLink></li>
</ul>
</div>
</div>
</div>
</div>
<div style="text-align: center;">
<h1>功能演示</h1>
<p>即刻体验人脸对比。请上传两张本地图片或提供图片URL对比人脸相似度。</p>
<p>该功能演示基于Baidu Detect API搭建</p>
</div>
<form id="form1" runat="server">
<div style="float: left; margin-top: 56px; margin-left: 200px;">
<br />
<div style="float: left; margin-right: 50px">
<br />
<asp:Image runat="server" ID="showPic1" ImageUrl="/img/demo-pic6.jpg" Style="z-index: 102; left: 20px; position: center; top: 49px;" Width="377px" Height="335px" />
<br />
<br />
<div style="float: left">
<input type="text" readonly="readonly" id="repre1" class="inputtext"/>
<input type="button" id="up1" value="上传图片1" class="btn" />
</div>
<asp:FileUpload ID="picFile1" runat="server" Width="152px" Style="visibility: hidden; float: left;" />
</div>
<div style="float: right; margin-right: 50px;">
<br />
<asp:Image runat="server" ID="showPic2" ImageUrl="/img/demo-pic6.jpg" Style="z-index: 102; left: 20px; position: center; top: 49px;" Width="377px" Height="335px" />
<br />
<br />
<div style="float: left">
<input type="text" readonly="readonly" id="repre2" class="inputtext" />
<input type="button" id="up2" value="上传图片2" class="btn" />
</div>
<asp:FileUpload ID="picFile2" runat="server" Width="152px" Style="visibility: hidden; float: left;" />
</div>
</div>
<div style="float: right; margin-top: 56px; margin-right: 200px;">
<div>
<asp:Label ID="tip" runat="server" Text="▼人脸对比相似度(数值越高,相似度越大)"></asp:Label>
</div>
<asp:TextBox ID="similarityNum" ReadOnly="true" TextMode="MultiLine" οnmοuseοver="this.style.borderColor='beige';this.style.backgroundColor='#CCCCCC'" runat="server" Height="332px" Style="font-family: 微软雅黑;background-color: #53868B; margin-top: 0px; font-size:20px;font-weight:bold;" Width="405px"></asp:TextBox>
<br />
<br />
<asp:Button ID="submit" runat="server" Text="对比检测" OnClick="submit_Click" CssClass="btn" />
</div>
</form>
<div>
<asp:Literal ID="message" runat="server" Text=""></asp:Literal>
</div>
<script src="/JS/jquery-3.2.1.min.js" charset="utf-8"></script>
<script>
$(document).ready(function () {
$("#up1").click(function () {
$("#picFile1").click();
});
$("#picFile1").change(function () {
$("#repre1").val($("#picFile1").val().trim());
});
$("#up2").click(function () {
$("#picFile2").click();
});
$("#picFile2").change(function () {
$("#repre2").val($("#picFile2").val().trim());
});
});
</script>
</body>
</html>
public partial class FaceMatch : System.Web.UI.Page
{
string script = "<script language='javascript'> {0} </script>";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submit_Click(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpResponse response = context.Response;
if (picFile1.FileName == "" || picFile2.FileName == "")
{
this.message.Text = string.Format(script, "alert(\"必须上传两个文件!\");");
return;
}
bool fileIsValid = false;
//如果确认了上传文件,则判断文件类型是否符合要求
if (this.picFile1.HasFile && this.picFile2.HasFile)
{
//获取上传文件的后缀
String fileExtension1 = System.IO.Path.GetExtension(this.picFile1.FileName).ToLower();
String fileExtension2 = System.IO.Path.GetExtension(this.picFile2.FileName).ToLower();
String[] restrictExtension = { ".jpg", ".png" };
//判断文件类型是否符合要求
for (int i = 0; i < restrictExtension.Length; i++)
{
if (fileExtension1 == restrictExtension[i])
{
for (int j = 0; j < restrictExtension.Length; j++)
{
if (fileExtension2 == restrictExtension[j])
fileIsValid = true;
}
}
//如果文件类型符合要求,调用SaveAs方法实现上传,并显示相关信息
if (fileIsValid == true)
{
//上传文件是否大于10M
if (picFile1.PostedFile.ContentLength > (10 * 1024 * 1024) || picFile1.PostedFile.ContentLength > (10 * 1024 * 1024))
{
this.message.Text = string.Format(script, "alert(\"上传的单个图片不能大于10MB!\");");
}
try
{
this.picFile1.SaveAs(Server.MapPath("~/File/") + picFile1.FileName);
this.picFile2.SaveAs(Server.MapPath("~/File/") + picFile2.FileName);
this.showPic1.ImageUrl = "~/File/" + picFile1.FileName;
this.showPic2.ImageUrl = "~/File/" + picFile2.FileName;
string similarity = new FaceMatching().matchFace(Server.MapPath("~/File/") + picFile1.FileName, Server.MapPath("~/File/") + picFile2.FileName);
this.similarityNum.Text = " 人脸对比相似度 \r\n\r\n" + "相似度指数(1~100): " + similarity;
}
catch
{
this.message.Text = string.Format(script, "alert(\"上传图片失败!\");");
}
finally
{
}
}
else
{
this.message.Text = string.Format(script, "alert(\"只能够上传后缀为.jpg,.png的文件!\");");
}
}
}
}
}