LAMPIRAN A : LISTING PROGRAM
private static double dist(double a, double b) {
double r;
if (System.Math.Abs(a) > System.Math.Abs(b)) {
r = b / a;
return (System.Math.Abs(a) * System.Math.Sqrt(1 + r * r)); }
else if (b != 0) {
r = a / b;
return (System.Math.Abs(b) * System.Math.Sqrt(1 + r * r)); }
else {
return (0.0); }
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Data.SqlClient; namespace Eigenfaces.Kelas {
class Koneksi {
SqlConnection con; public bool test() {
try {
con = new SqlConnection("Data Source=COMPAQ510\\SQLEXPRESS; Initial Catalog=EIGEN; Integrated Security=SSPI;");
con.Open(); }
catch {
return false; }
return true; }
public SqlConnection getCon() {
return con; }
public SqlConnection tutupKoneksi() {
con.Close(); return con; }
public PCA(double[][] inVectors) {
meanValues = calcMeanValues(inVectors);
vectorsZeroMean = Vector.addVecToSet(inVectors, Vector.scale(-1.0, meanValues));
covarianceMatrix = Matrix.scale(Matrix.square(vectorsZeroMean), 1.0 / Matrix.getNumOfColumns(inVectors));
EigenValueDecompositionSymm eigenDeco = new EigenValueDecompositionSymm(covarianceMatrix);
eigenVectors = eigenDeco.EigenVectors; eigenValues = eigenDeco.EigenValues;
resVectors = Matrix.mult(Matrix.transpose(eigenVectors), vectorsZeroMean);
}
private static double[] calcMeanValues(double[][] inVectors) {
int m = Matrix.getNumOfRows(inVectors); int n = Matrix.getNumOfColumns(inVectors); double[] meanValues = Vector.newVector(m); for (int i = 0; i < m; ++i)
{
meanValues[i] = 0.0;
for (int j = 0; j < n; ++j) {
meanValues[i] += inVectors[i][j]; }
meanValues[i] /= n; }
return (meanValues); }
public PCA(double[][] inVectors) {
meanValues = calcMeanValues(inVectors);
vectorsZeroMean = Vector.addVecToSet(inVectors, Vector.scale(-1.0, meanValues));
covarianceMatrix = Matrix.scale(Matrix.square(vectorsZeroMean), 1.0 / Matrix.getNumOfColumns(inVectors));
EigenValueDecompositionSymm eigenDeco = new EigenValueDecompositionSymm(covarianceMatrix);
eigenVectors = eigenDeco.EigenVectors; eigenValues = eigenDeco.EigenValues;
resVectors = Matrix.mult(Matrix.transpose(eigenVectors), vectorsZeroMean);
}
private static double[] calcMeanValues(double[][] inVectors) {
int m = Matrix.getNumOfRows(inVectors); int n = Matrix.getNumOfColumns(inVectors); double[] meanValues = Vector.newVector(m); for (int i = 0; i < m; ++i)
{
meanValues[i] = 0.0;
for (int j = 0; j < n; ++j) {
meanValues[i] += inVectors[i][j]; }
meanValues[i] /= n; }
return (meanValues); }
using System.Text; Math.Floor(yAsal) < 0 || Math.Ceiling(yAsal) > h - 1)
+ wxL * (1 - wyT) * bmp.GetPixel(xL, yB).R
+ (1 - wxL) * (1 - wyT) * bmp.GetPixel(xR, yB).R);
if (hasil > 255) {
hasil = 255; }
bmp2.SetPixel(x1, y1, Color.FromArgb((int)hasil, (int)hasil, (int)hasil));
} } }
return bmp2; }
using System.Text;
private static System.String fillString(System.String in_Renamed, int len)
}
public static double[][] addVecToSet(double[][] vecSet, double[] addVec)
{
int m = Matrix.getNumOfRows(vecSet); int n = Matrix.getNumOfColumns(vecSet); double[][] res = Matrix.newMatrix(m, n); for (int i = 0; i < m; ++i)
{
double add = addVec[i]; for (int j = 0; j < n; ++j) {
res[i][j] = vecSet[i][j] + add; }
}
return (res); }
} }
using System.Collections.Generic;
public partial class Pengenalan2 : Form {
detector.SearchMode = ObjectDetectorSearchMode.Average; detector.ScalingFactor = 1.5f;
g.Dispose();
nama.Add((String)dataReader[0]);
private void btnAmbilGambar_Click(object sender, EventArgs e) {
pictureBox2.Image = gambar; bersih();
}
}
private void Form_closed(object sender, EventArgs e) {
timer.Stop(); capture.Stop(); capture.Dispose(); }
Percobaan ke lima
Struktur Database Table DATATRAIN
using System.Data;
detector.SearchMode = ObjectDetectorSearchMode.Average; detector.ScalingFactor = 1.5f;
gambar = (Bitmap)cropImage;
private void Training2_Load(object sender, EventArgs e) {
capture = new Capture(); timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick); timer.Interval = new TimeSpan(0, 0, 0, 0, 1);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; timer.Start();
}
private void training_closed(object sender, EventArgs e) {
timer.Stop(); capture.Stop(); capture.Dispose(); }
private void btnAmbilGambar_Click(object sender, EventArgs e) {