LISTING PROGRAM
Form Home.cs
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.IO;
namespace SURF_Algorithm {
public partial class Form_Home : Form {
public Form_Home() {
InitializeComponent();
this.Closing += (this.Keluar); }
void Keluar(object sender, CancelEventArgs e) {
if (MessageBox.Show("Tutup Aplikasi ?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) Application.ExitThread();
else
e.Cancel = true; }
private void keluarToolStripMenuItem_Click(object sender, EventArgs e) {
Close(); }
private void videoToolStripMenuItem_Click(object sender, EventArgs e) {
Form_Video FV = new Form_Video(); Hide(); FV.Show();
}
private void Form_Home_Load(object sender, EventArgs e) {
Directory.CreateDirectory(Application.StartupPath + "\\Data"); Directory.CreateDirectory(Application.StartupPath +
"\\Data\\Frame");
Directory.CreateDirectory(Application.StartupPath + "\\Data\\Video");
}
{
Form_SURF FS = new Form_SURF(); Hide(); FS.Show();
} } }
Form Video.cs
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; using System.IO;
namespace SURF_Algorithm {
public partial class Form_Video : Form {
public Form_Video() {
InitializeComponent();
this.Closing += (this.Keluar); }
void Keluar(object sender, CancelEventArgs e) {
Form_Home FH = new Form_Home(); FH.Show();
}
private void Form_Video_Load(object sender, EventArgs e) {
Tampil_Data(); }
void Tampil_Data() {
Konfigurasi.Koneksi();
Konfigurasi.DA = new OleDbDataAdapter("SELECT * FROM `Tabel Video` ORDER BY Nama ASC", Konfigurasi.CONN);
Konfigurasi.DS = new DataSet(); Konfigurasi.DS.Clear();
Konfigurasi.DA.Fill(Konfigurasi.DS, "Tabel Video"); DGV.DataSource = Konfigurasi.DS.Tables["Tabel Video"]; DGV.Refresh();
}
private void btn_tambah_Click(object sender, EventArgs e) {
FTV.ShowDialog(); }
private void btn_hapus_Click(object sender, EventArgs e) {
groupBox2.Text.Replace("Player : ", "") + " ?", "Konfirmasi",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) Video` WHERE Nama = '" + groupBox2.Text.Replace("Player : ", "") + "'", Konfigurasi.CONN);
private void txt_cari_TextChanged(object sender, EventArgs e) {
try {
Konfigurasi.Koneksi();
private void DGV_CellClick(object sender, DataGridViewCellEventArgs e) {
try {
groupBox2.Text = "Player : " + DGV.Rows[e.RowIndex].Cells[0].Value.ToString();
WMP.URL = DGV.Rows[e.RowIndex].Cells[3].Value.ToString(); }
catch {
} }
private void btn_reload_Click(object sender, EventArgs e) {
Tampil_Data(); }
private void DGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
} }}
Form Tambah Video.cs
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Windows.Forms; using System.Threading; using Emgu.CV;
using Emgu.CV.Structure; using Emgu.Util;
using System.Drawing.Imaging; using System.IO;
using System.Data.OleDb;
namespace SURF_Algorithm {
public partial class Form_Tambah_Video : Form {
private Capture _capture = null; Image<Bgr, Byte> frame;
string Tnama, Tdurasi, Tframe, Tlokasi, TLFrame;
public Form_Tambah_Video() {
InitializeComponent(); }
private void ReleaseData() {
if (_capture != null) _capture.Dispose(); }
private void ProcessFrame(object sender, EventArgs arg) {
try {
Framesno =
_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES); frame = _capture.QueryFrame();
if (frame != null) {
pictureBox1.Image = frame.ToBitmap();
if (Video_seek.Value + (int)(FrameRate) < Video_seek.Maximum)
{
Video_seek.Value = (int)(Framesno); double time_index =
_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_MSEC); Time_Label.Text = "Time: " +
TimeSpan.FromMilliseconds(time_index).ToString().Substring(0, 8); double framenumber =
_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES); Frame_lbl.Text = "Frame: " + framenumber.ToString();
SaveImage(framenumber.ToString()); Video_seek.Value += (int)FrameRate;
_capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, Video_seek.Value);
}
Thread.Sleep((int)(1000.0 / FrameRate)); }
}
catch (Exception ex) {
MessageBox.Show(ex.Message.ToString()); }
}
public void SaveImage(string frameNumber) {
using (var m = new MemoryStream()) {
pictureBox1.Image.Save(m, ImageFormat.Jpeg);
var path = TLFrame +
Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + "-" + frameNumber + ".jpg";
img.Save(path); }
}
_capture.Stop(); '"+ Tdurasi +"', '"+ Tframe +"', '"+ Tlokasi +"')";
Konfigurasi.Koneksi();
Form Player.cs
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb;
namespace SURF_Algorithm {
public partial class Form_Player : Form {
public string video;
public Form_Player() {
InitializeComponent();
this.Closing += (this.Keluar); }
void Keluar(object sender, CancelEventArgs e) {
WMP.Dispose(); }
private void Form_Player_Load(object sender, EventArgs e) {
Konfigurasi.Koneksi();
Konfigurasi.CMD = new OleDbCommand("SELECT Lokasi FROM `Tabel Video` WHERE Nama like '%" + video + "%'", Konfigurasi.CONN);
Konfigurasi.DR = Konfigurasi.CMD.ExecuteReader(); Konfigurasi.DR.Read();
WMP.URL = Konfigurasi.DR.GetString(0); this.Text += " - " + video;
} }}
Form SURF.cs
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using Emgu.CV;
namespace SURF_Algorithm {
public partial class Form_SURF : Form {
public Form_SURF() {
InitializeComponent();
this.Closing += (this.Keluar); }
void Keluar(object sender, CancelEventArgs e) {
Form_Home FH = new Form_Home(); FH.Show();
}
private void Form_SURF_Load(object sender, EventArgs e) {
Reset(); }
private void btn_pil_gambar_Click(object sender, EventArgs e) {
ofd.Filter = "Image Files |*.gif;*.jpg;*.jpeg;*.bmp;*.wmf;*.png"; ofd.FileName = "";
if (ofd.ShowDialog() == DialogResult.OK) {
pb_gbr1.Image = Image.FromFile(ofd.FileName); txt_pil_gambar.Text = ofd.FileName;
} }
private void btn_reset_Click(object sender, EventArgs e) {
Reset(); }
private void Reset() {
btn_pil_gambar.Focus(); txt_log.Text = "--> "; txt_pil_gambar.Clear(); lbl_wp.Text = "- Detik"; lbl_th.Text = "0 Video";
pb_gbr1.Image = Properties.Resources.Temp; pb_gbr2.Image = Properties.Resources.Temp; pb_gbr_hasil.Image = Properties.Resources.Temp; lb_video.Items.Clear();
}
private void bw_DoWork(object sender, DoWorkEventArgs e) {
this.Cursor = Cursors.WaitCursor; long matchTime;
double Waktu_Proses = 0.0;
string[] Folders = Directory.GetDirectories(Application.StartupPath
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Cursor = Cursors.Default;
MessageBox.Show("Proses Selesai", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
btn_cari.Enabled = true; btn_reset.Enabled = true; btn_pil_gambar.Enabled = true; }
groupBox4.BringToFront(); } else
{
groupBox4.Left = 507; groupBox4.Top = 77;
groupBox4.Width = 165; groupBox4.Height = 165; }
}
private void btn_cari_Click(object sender, EventArgs e) {
if (txt_pil_gambar.Text == "") {
MessageBox.Show("Pilih Gambar Terlebih Dahulu", "Pesan", MessageBoxButtons.OK, MessageBoxIcon.Information);
return; }
lbl_wp.Text = "- Detik"; lbl_th.Text = "0 Video"; lb_video.Items.Clear();
bw.RunWorkerAsync();
Control.CheckForIllegalCrossThreadCalls = false;
btn_cari.Enabled = false; btn_reset.Enabled = false; btn_pil_gambar.Enabled = false; }
private void lb_video_SelectedIndexChanged(object sender, EventArgs e) {
try {
Form_Player FP = new Form_Player();
FP.video = lb_video.SelectedItem.ToString(); FP.ShowDialog();
} catch {} } }}
SURF.CS
using System;
using System.Collections.Generic; using System.Diagnostics;
using System.Drawing;
using Emgu.CV.CvEnum;
/// <param name="modelImageFileName">The model image</param> /// <param name="observedImageFileName">The observed image</param> /// <param name="matchTime">The output total time for computing the homography matrix.</param>
/// <returns>The model image and observed image, the matched features and homography projection.</returns>
public static Image<Bgr, Byte> Draw(String modelImageFileName, String observedImageFileName, out long matchTime, out bool Cocok)
using (GpuMat<float> gpuObservedKeyPoints = gpuModelDescriptors, gpuMatchIndices, gpuMatchDist, k, null, stream); indices = new Matrix<int>(gpuMatchIndices.Size); while we are waiting for the stream to complete.
watch = Stopwatch.StartNew();
// extract features from the observed image
observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
Matrix<float> observedDescriptors =
surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints); BruteForceMatcher<float> matcher = new
BruteForceMatcher<float>(DistanceType.L2); matcher.Add(modelDescriptors);
indices = new Matrix<int>(observedDescriptors.Rows, k); using (Matrix<float> dist = new
Matrix<float>(observedDescriptors.Rows, k)) {
matcher.KnnMatch(observedDescriptors, indices, dist, k, null);
mask = new Matrix<byte>(dist.Rows, 1); mask.SetValue(255);
Features2DToolbox.VoteForUniqueness(dist, uniquenessThreshold, mask);
}
int nonZeroCount = CvInvoke.cvCountNonZero(mask); if (nonZeroCount >= 4)
{
nonZeroCount =
Features2DToolbox.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, indices, mask, 1.5, 20);
if (nonZeroCount >= 4) homography =
Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints, observedKeyPoints, indices, mask, 2);
}
watch.Stop(); }
//Draw the matched keypoints
Image<Bgr, Byte> result = Features2DToolbox.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints,
indices, new Bgr(255, 255, 255), new Bgr(255, 255, 255), mask, Features2DToolbox.KeypointDrawType.DEFAULT);
#region draw the projected region on the image if (homography != null)
{ //draw a rectangle along the projected model Cocok = true;
Rectangle rect = modelImage.ROI; PointF[] pts = new PointF[] { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Bottom), new PointF(rect.Right, rect.Top), new PointF(rect.Left, rect.Top)}; homography.ProjectPoints(pts);
result.DrawPolyline(Array.ConvertAll<PointF, Point>(pts, Point.Round), true, new Bgr(Color.Red), 5);
Cocok = false; }
#endregion
matchTime = watch.ElapsedMilliseconds;
return result; }
}}
Program.cs
using System;
using System.Collections.Generic; using System.Linq;
using System.Threading.Tasks; using System.Windows.Forms;
namespace SURF_Algorithm {
static class Program {
/// <summary>
/// The main entry point for the application. /// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form_Home());
} }}
Konfigurasi.cs
using System; using System.Data; using System.Data.OleDb; using System.Windows.Forms;
namespace SURF_Algorithm {
public static class Konfigurasi {
public static OleDbConnection CONN; public static OleDbDataAdapter DA; public static DataSet DS;
public static OleDbCommand CMD; public static OleDbDataReader DR;
public static void Koneksi() {
try {
const string Q = "provider=microsoft.jet.oledb.4.0; data source = DB.mdb;";
CONN = new OleDbConnection(Q);
if (CONN.State == ConnectionState.Closed) {
CONN.Open(); }
}
catch (Exception e) {
MessageBox.Show(e.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);