Está en la página 1de 4

CODIGO FUENTE

using
using
using
using
using
using

System;
System.Drawing;
System.Collections;
System.ComponentModel;
System.Windows.Forms;
System.Data;

namespace monedas
{
public class Form1 : System.Windows.Forms.Form
{
double r1=38.04,r5=42.87,r10=34.83,r25=47.33,r50=59.81;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void buttonStart_Click(object sender,
System.EventArgs e)
{
webCam2.Start();
}
private void buttonStop_Click(object sender,
System.EventArgs e)
{
webCam2.Stop();
}
private void cap_Click(object sender, System.EventArgs e)
{
pictureBox1.Image=webCam2.Imagen;
//pictureBox3.Image=null;

}
private void webCam2_CambioImagen()
{
//pictureBox1.Image=webCam2.Imagen;

e)

}
private void binario_Click(object sender, System.EventArgs
{

int x,y,G;
Color color;
Bitmap ImaIn= new Bitmap(this.pictureBox1.Image);
int ancho=ImaIn.Width;
int alto=ImaIn.Height;
int umbral = Convert.ToInt16(this.Tumbral.Text);
Bitmap ImaOut=new Bitmap(ancho,alto);
for(x=0;x < ancho;x++)
for(y=0;y<alto; y++)
{
color=ImaIn.GetPixel(x,y);
G=(color.R+color.G+color.B)/3;
if((G>umbral)||(x<5)||(y<5))
{
ImaOut.SetPixel(x,y,Color.Black);
}
else
{
ImaOut.SetPixel(x,y,Color.Red);
}
}
this.pictureBox2.Image=ImaOut;

}
private void buttonMoment_Click(object sender,
System.EventArgs e)
{
int x,y;
Color C;
Bitmap ImaIn= new Bitmap(this.pictureBox2.Image);
int ancho= ImaIn.Width;
int alto= ImaIn.Height;
double m00=0,m10=0,m01=0;
double Xc,Yc,Area;
double
u10=0,u01=0,u11=0,u20=0,u02=0,u21=0,u22=0,u12=0,u30=0,u03=0;
double Hu1,Hu2,Hu3,Hu4,Hu5,Hu6,Hu7;
//calculo del area y las cooordenadas del centroide
for(x=0;x<ancho;x++)
for (y=0;y<alto;y++)
{
C=ImaIn.GetPixel(x,y);
if(C.R>200)
{
m00++;
m10=m10+x;
m01=m01+y;
}
}
//Area y centroide

Area=m00;
Xc=m10/m00;
Yc=m01/m00;
this.textBox1.Text=Convert.ToString(Area);
this.textBox2.Text=Convert.ToString(Xc);
this.textBox3.Text=Convert.ToString(Yc);
// momentos centrales u
for(x=0;x<ancho;x++)
for(y=0;y<alto;y++)
{
C=ImaIn.GetPixel(x,y);
if(C.R>200)
{
u10= u10 +(x- Convert.ToInt32(Xc));
u01= u01 +(y-Convert.ToInt32(Yc));
u20= u20 +Math.Pow((xConvert.ToInt32(Xc)),2);
u02= u02 +Math.Pow((yConvert.ToInt32(Yc)),2);
u30= u30 +Math.Pow((xConvert.ToInt32(Xc)),3);
u03= u03 +Math.Pow((xConvert.ToInt32(Xc)),3);
u11= u11 +(xConvert.ToInt32(Xc))*(y-Convert.ToInt32(Yc));
u21= u21 +Math.Pow((xConvert.ToInt32(Xc)),2)*(y-Convert.ToInt32(Yc));
u12= u12 +(xConvert.ToInt32(Xc))*Math.Pow((y-Convert.ToInt32(Yc)),2);
u22= u22 +Math.Pow((xConvert.ToInt32(Xc)),2)*Math.Pow((y-Convert.ToInt32(Yc)),2);
}
}
u20= u20/ Math.Pow(m00,2);
u02= u02/ Math.Pow(m00,2);
u30= u30/ Math.Pow(m00,2.5);
u03= u03/ Math.Pow(m00,2.5);
u11= u11/ Math.Pow(m00,2);
u21= u21/ Math.Pow(m00,2.5);
u12= u12/ Math.Pow(m00,2.5);
u22= u22/ Math.Pow(m00,3);
//momentos de Hu
Hu1= u20+u02;
Hu2= Math.Pow((u20-u02),2)+4*Math.Pow(u11,2);
Hu3= Math.Pow((u30-3*u12),2)+Math.Pow((3*u21-u30),2);
Hu4= Math.Pow((u30+u12),2)+Math.Pow((3*u21 - u03),2);
Hu5= (u30-3*u12)* (u30+u12)*(Math.Pow ((u30+u12),2)3*Math.Pow((u21+u03),2))+ (3*u21u03)*(u21+u03)*(3*Math.Pow((u30+u12),2) - Math.Pow((u21+u03),2));
Hu6= (u20-u02)*(Math.Pow((u30+u12),2)Math.Pow((u21+u03),2));
Hu7= (3*u21-u03)*(u30+u12)*(Math.Pow((u30+u12),2)3*Math.Pow((u21+u03),2))+ (3*u12u03)*(u21+u03)*(3*Math.Pow((u30+u12),2)- Math.Pow((u21+u03),2));
this.listBox1.Items.Add(Hu1);
this.listBox1.Items.Add(Hu2);
this.listBox1.Items.Add(Hu3);
this.listBox1.Items.Add(Hu4);
this.listBox1.Items.Add(Hu5);
this.listBox1.Items.Add(Hu6);

this.listBox1.Items.Add(Hu7);
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu1))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu2))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu3))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu4))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu5))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu6))));
this.listBox2.Items.Add(Math.Abs
(Math.Log10(Math.Abs(Hu7))));
this.listBox1.Items.Add(" ");
this.listBox2.Items.Add(" ");
//imprime los momentos centrales normalizados
this.textBox4.Text= Convert.ToString(u10);
this.textBox5.Text= Convert.ToString(u20);
this.textBox6.Text= Convert.ToString(u30);
this.textBox7.Text= Convert.ToString(u01);
this.textBox8.Text= Convert.ToString(u02);
this.textBox9.Text= Convert.ToString(u03);
//grafico del centroide
Graphics g= Graphics.FromImage(ImaIn);
Pen pen = new Pen(Color.Blue,3);
g.DrawLine(pen,0,Convert.ToInt16(Yc),ancho,Convert.ToInt16(Yc));
g.DrawLine(pen,Convert.ToInt16(Xc),0,Convert.ToInt16(Xc),alto);
this.pictureBox2.Image=ImaIn;
}
private void buttonRec_Click(object sender,
System.EventArgs e)
{
double area=Convert.ToDouble(textBox1.Text);
double radio=Math.Sqrt(area/(2*3.14159));
if ((r1>radio-1.5)&(r1<radio+1.5))
moneda.Text="centavo";
if ((r10>radio-2)&(r10<radio+2))
moneda.Text="Diez centavos";
if ((r5>radio-2)&(r5<radio+2))
moneda.Text="Cinco centavos";
if ((r25>radio-3)&(r25<radio+3))
moneda.Text="Veinticinco centavos";
if ((r50>radio-6)&(r50<radio+6))
moneda.Text="Cincuenta centavos";
}

textBox14.Text=Convert.ToString(radio);

private void buttonClose_Click(object sender,


System.EventArgs e)
{
Application.Exit();
}}}