基本信息
源码名称:基于MATLAB混合编程图像分析及数据处理
源码大小:1.92KB
文件格式:.sln
开发语言:C#
更新时间:2016-01-04
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
【基于C#语言开发人脸皮肤图像分析软件】
【】
【
#region 截图方法
/// <summary>
/// 剪裁 -- 用GDI
/// </summary>
/// <param name="b">原始Bitmap</param>
/// <param name="StartX">开始坐标X</param>
/// <param name="StartY">开始坐标Y</param>
/// <param name="iWidth">宽度</param>
/// <param name="iHeight">高度</param>
/// <returns>剪裁后的Bitmap</returns>
public static Bitmap CutImage(Image b, int StartX, int StartY, int iWidth, int iHeight)
{
if (b == null)
{
return null;
}
int w = b.Width;
int h = b.Height;
Bitmap bmpOut = null;
try
{
bmpOut = new Bitmap(iWidth, iHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose();
return bmpOut;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
b.Dispose();
// bmpOut.Dispose();
}
}
/// <summary>
/// 按照指定大小缩放图片,但是为了保证图片宽高比自动截取
/// </summary>
/// <param name="srcImage"></param>
/// <param name="iWidth"></param>
/// <param name="iHeight"></param>
/// <returns></returns>
public static Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
{
Bitmap cutedImage=null;
try
{
int newW = 1000;
int newH = 1000;
int newX = 0;
int newY = 0;
//取得符合比例的临时文件
cutedImage = CutImage(ImageLocation1, newX, newY, newW, newH);
// 保存到的文件
// Bitmap b = new Bitmap(iWidth, iHeight);
cutedImage.Save(path3, System.Drawing.Imaging.ImageFormat.Bmp);
return cutedImage;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
ImageLocation1.Dispose();
cutedImage.Dispose();
}
}
#endregion
void UsingFileSystemWatcher()
{
FileSystemWatcher fswWatcher = new FileSystemWatcher();
fswWatcher.Path = path;
fswWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.LastAccess;
fswWatcher.Filter = "*.*";
fswWatcher.IncludeSubdirectories = true;
#region 实例化触发的事件(已定)
fswWatcher.Created = new FileSystemEventHandler(fswWatcher_Created);
fswWatcher.Changed = new FileSystemEventHandler(fswWatcher_Changed);
fswWatcher.Renamed = new RenamedEventHandler(fswWatcher_Renamed);
fswWatcher.Deleted = new FileSystemEventHandler(fswWatcher_Deleted);
#endregion
//获取或设置一个值,该值指示是否启用此组件。
fswWatcher.EnableRaisingEvents = true;
}//定义监控文件夹的方法
#region 监控图片传入
void fswWatcher_Created(object sender, FileSystemEventArgs e)
{
#region 修改图片名称并转存
System.Drawing.Image ImageLocation1=null;
try
{
string path2 = @"C:\copy2\" newName;
System.IO.File.Copy(e.FullPath, path2, true);
path3 = path2.Replace("copy2", "copy");
//Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
ImageLocation1 = System.Drawing.Image.FromFile(path2);
SizeImageWithOldPercent(ImageLocation1, ImageLocation1.Width, ImageLocation1.Height);//单独做成方法
}
catch
{
//
}
finally {
if (ImageLocation1 != null)
{
ImageLocation1.Dispose();
}
}
#endregion
}
#region 监控备用
private void ModifyFileName(string p, string p_2)
{
throw new NotImplementedException();
}
void fswWatcher_Changed(object sender, FileSystemEventArgs e)
{
}
void fswWatcher_Renamed(object sender, RenamedEventArgs e)
{
}
void fswWatcher_Deleted(object sender, FileSystemEventArgs e)
{
//DirectoryInfo dir = new DirectoryInfo(path);
//dir.Create();//自行判断一下是否存在。
}
#endregion
#endregion
private void Form1_Load(object sender, EventArgs e)
{
}
#region 皮肤算法集
private void 光泽度(object sender, EventArgs e)
{
try
{
test6.Class6 exp6 = new test6.Class6();
MWArray[] t = exp6.guangzedu(1);
MWNumericArray t1 = (MWNumericArray)t[0];
double[,] t2 = (double[,])t1.ToArray(MWArrayComponent.Real);
double t3 = t2[0, 0];
str6 = t3.ToString("N");
textBox6.Text = str6;
str6 = null;
}
catch (Exception)
{
// MessageBox.Show("图片错误,请重新选择!");
//Close();
}
finally
{
}
}
private void 粗糙度(object sender, EventArgs e)
{
try
{
test1.Class1 exp1 = new test1.Class1();
MWArray[] x = exp1.cucaodu(1);
MWNumericArray x1 = (MWNumericArray)x[0];
double[,] x2 = (double[,])x1.ToArray(MWArrayComponent.Real);
double x3 = x2[0, 0];
str1= x3.ToString("N");//将隐式int转换为string类型
textBox1.Text = str1;
str1 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 纹理(object sender, EventArgs e)
{
try
{
test2.Class2 exp2 = new test2.Class2();
MWArray[] a = exp2.wenli(1);
MWNumericArray a1 = (MWNumericArray)a[0];
double[,] b2 = (double[,])a1.ToArray(MWArrayComponent.Real);
double b3 = b2[0, 0];
str2 = b3.ToString("N");
textBox2.Text = str2;
str2 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 色泽(object sender, EventArgs e)
{
try
{
test3.Class3 exp3 = new test3.Class3();
MWArray[] q = exp3.seze(1);
MWNumericArray q1 = (MWNumericArray)q[0];
double[,] q2 = (double[,])q1.ToArray(MWArrayComponent.Real);
double q3 = q2[0, 0];
str3 = q3.ToString("N");
textBox3.Text = str3;
str3 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 弹性(object sender, EventArgs e)
{
try
{
test4.Class4 exp4 = new test4.Class4();
MWArray[] w = exp4.tanxing(1);
MWNumericArray w1 = (MWNumericArray)w[0];
double[,] w2 = (double[,])w1.ToArray(MWArrayComponent.Real);
double w3 = w2[0, 0];
str4 = w3.ToString("N");
textBox4.Text = str4;
str4 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 水份(object sender, EventArgs e)
{
try
{
test5.Class5 exp5 = new test5.Class5();
MWArray[] r = exp5.water(1);
MWNumericArray r1 = (MWNumericArray)r[0];
double[,] r2 = (double[,])r1.ToArray(MWArrayComponent.Real);
double r3 = r2[0, 0];
str5 = r3.ToString("N");
textBox5.Text = str5;
str5 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
#endregion
private void button2_Click_1(object sender, EventArgs e)
{
if (qq == 0)
{
Thread t = new Thread(DoWork);
t.Start();
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string a = textBox6.Text.ToString();
ProgressBar1.ActiveForm.Close();
if (a == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (a == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
t.Abort();
qq ;
}
else
{
Thread l = new Thread(DoWork1);
l.Start();
textBox1.Text = first.ToString("G");
textBox2.Text = first.ToString("G");
textBox3.Text = first.ToString("G");
textBox4.Text = first.ToString("G");
textBox5.Text = first.ToString("G");
textBox6.Text = first.ToString("G");
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string zz = textBox6.Text.ToString();
ProgressBar2.ActiveForm.Close();
if (zz == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (zz == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
l.Abort();
}
}
【基于C#语言开发人脸皮肤图像分析软件】
【】
【
#region 截图方法
/// <summary>
/// 剪裁 -- 用GDI
/// </summary>
/// <param name="b">原始Bitmap</param>
/// <param name="StartX">开始坐标X</param>
/// <param name="StartY">开始坐标Y</param>
/// <param name="iWidth">宽度</param>
/// <param name="iHeight">高度</param>
/// <returns>剪裁后的Bitmap</returns>
public static Bitmap CutImage(Image b, int StartX, int StartY, int iWidth, int iHeight)
{
if (b == null)
{
return null;
}
int w = b.Width;
int h = b.Height;
Bitmap bmpOut = null;
try
{
bmpOut = new Bitmap(iWidth, iHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose();
return bmpOut;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
b.Dispose();
// bmpOut.Dispose();
}
}
/// <summary>
/// 按照指定大小缩放图片,但是为了保证图片宽高比自动截取
/// </summary>
/// <param name="srcImage"></param>
/// <param name="iWidth"></param>
/// <param name="iHeight"></param>
/// <returns></returns>
public static Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
{
Bitmap cutedImage=null;
try
{
int newW = 1000;
int newH = 1000;
int newX = 0;
int newY = 0;
//取得符合比例的临时文件
cutedImage = CutImage(ImageLocation1, newX, newY, newW, newH);
// 保存到的文件
// Bitmap b = new Bitmap(iWidth, iHeight);
cutedImage.Save(path3, System.Drawing.Imaging.ImageFormat.Bmp);
return cutedImage;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
ImageLocation1.Dispose();
cutedImage.Dispose();
}
}
#endregion
void UsingFileSystemWatcher()
{
FileSystemWatcher fswWatcher = new FileSystemWatcher();
fswWatcher.Path = path;
fswWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.LastAccess;
fswWatcher.Filter = "*.*";
fswWatcher.IncludeSubdirectories = true;
#region 实例化触发的事件(已定)
fswWatcher.Created = new FileSystemEventHandler(fswWatcher_Created);
fswWatcher.Changed = new FileSystemEventHandler(fswWatcher_Changed);
fswWatcher.Renamed = new RenamedEventHandler(fswWatcher_Renamed);
fswWatcher.Deleted = new FileSystemEventHandler(fswWatcher_Deleted);
#endregion
//获取或设置一个值,该值指示是否启用此组件。
fswWatcher.EnableRaisingEvents = true;
}//定义监控文件夹的方法
#region 监控图片传入
void fswWatcher_Created(object sender, FileSystemEventArgs e)
{
#region 修改图片名称并转存
System.Drawing.Image ImageLocation1=null;
try
{
string path2 = @"C:\copy2\" newName;
System.IO.File.Copy(e.FullPath, path2, true);
path3 = path2.Replace("copy2", "copy");
//Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
ImageLocation1 = System.Drawing.Image.FromFile(path2);
SizeImageWithOldPercent(ImageLocation1, ImageLocation1.Width, ImageLocation1.Height);//单独做成方法
}
catch
{
//
}
finally {
if (ImageLocation1 != null)
{
ImageLocation1.Dispose();
}
}
#endregion
}
#region 监控备用
private void ModifyFileName(string p, string p_2)
{
throw new NotImplementedException();
}
void fswWatcher_Changed(object sender, FileSystemEventArgs e)
{
}
void fswWatcher_Renamed(object sender, RenamedEventArgs e)
{
}
void fswWatcher_Deleted(object sender, FileSystemEventArgs e)
{
//DirectoryInfo dir = new DirectoryInfo(path);
//dir.Create();//自行判断一下是否存在。
}
#endregion
#endregion
private void Form1_Load(object sender, EventArgs e)
{
}
#region 皮肤算法集
private void 光泽度(object sender, EventArgs e)
{
try
{
test6.Class6 exp6 = new test6.Class6();
MWArray[] t = exp6.guangzedu(1);
MWNumericArray t1 = (MWNumericArray)t[0];
double[,] t2 = (double[,])t1.ToArray(MWArrayComponent.Real);
double t3 = t2[0, 0];
str6 = t3.ToString("N");
textBox6.Text = str6;
str6 = null;
}
catch (Exception)
{
// MessageBox.Show("图片错误,请重新选择!");
//Close();
}
finally
{
}
}
private void 粗糙度(object sender, EventArgs e)
{
try
{
test1.Class1 exp1 = new test1.Class1();
MWArray[] x = exp1.cucaodu(1);
MWNumericArray x1 = (MWNumericArray)x[0];
double[,] x2 = (double[,])x1.ToArray(MWArrayComponent.Real);
double x3 = x2[0, 0];
str1= x3.ToString("N");//将隐式int转换为string类型
textBox1.Text = str1;
str1 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 纹理(object sender, EventArgs e)
{
try
{
test2.Class2 exp2 = new test2.Class2();
MWArray[] a = exp2.wenli(1);
MWNumericArray a1 = (MWNumericArray)a[0];
double[,] b2 = (double[,])a1.ToArray(MWArrayComponent.Real);
double b3 = b2[0, 0];
str2 = b3.ToString("N");
textBox2.Text = str2;
str2 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 色泽(object sender, EventArgs e)
{
try
{
test3.Class3 exp3 = new test3.Class3();
MWArray[] q = exp3.seze(1);
MWNumericArray q1 = (MWNumericArray)q[0];
double[,] q2 = (double[,])q1.ToArray(MWArrayComponent.Real);
double q3 = q2[0, 0];
str3 = q3.ToString("N");
textBox3.Text = str3;
str3 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 弹性(object sender, EventArgs e)
{
try
{
test4.Class4 exp4 = new test4.Class4();
MWArray[] w = exp4.tanxing(1);
MWNumericArray w1 = (MWNumericArray)w[0];
double[,] w2 = (double[,])w1.ToArray(MWArrayComponent.Real);
double w3 = w2[0, 0];
str4 = w3.ToString("N");
textBox4.Text = str4;
str4 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 水份(object sender, EventArgs e)
{
try
{
test5.Class5 exp5 = new test5.Class5();
MWArray[] r = exp5.water(1);
MWNumericArray r1 = (MWNumericArray)r[0];
double[,] r2 = (double[,])r1.ToArray(MWArrayComponent.Real);
double r3 = r2[0, 0];
str5 = r3.ToString("N");
textBox5.Text = str5;
str5 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
#endregion
private void button2_Click_1(object sender, EventArgs e)
{
if (qq == 0)
{
Thread t = new Thread(DoWork);
t.Start();
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string a = textBox6.Text.ToString();
ProgressBar1.ActiveForm.Close();
if (a == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (a == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
t.Abort();
qq ;
}
else
{
Thread l = new Thread(DoWork1);
l.Start();
textBox1.Text = first.ToString("G");
textBox2.Text = first.ToString("G");
textBox3.Text = first.ToString("G");
textBox4.Text = first.ToString("G");
textBox5.Text = first.ToString("G");
textBox6.Text = first.ToString("G");
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string zz = textBox6.Text.ToString();
ProgressBar2.ActiveForm.Close();
if (zz == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (zz == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
l.Abort();
}
}