I am working on writing a program for my capstone, using the Verilook 4.0, and I am having a dilemma.
It seems like if I wanted to do the face detection preview, I would need to be using a NLview control box instead of a standard picturebox. Is this true? In either case, could someone give me a suggestion on how to go about this? I have been stuck on this a while. My program currently enrolls a user, can identify them, and a few other things. I would like to implement the face detection preview...
I can see two options:
1. Figure out how to replace my picturebox with a NLview control box
2. Figure out how to draw the "green" boxes on the screen.
I have been looking through the tutorial all day, but have not gotten very far.
If it helps, here is my code:
- Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NickPicture;
using System.Threading;
using Neurotec;
using Neurotec.Images;
using Neurotec.Cameras;
using Neurotec.Biometrics;
using Neurotec.Biometrics.Gui;
namespace NickPicture
{
public partial class Form1 : Form
{
//globally sets a reference to my database class
theDatabase imagesDB = new theDatabase();
private volatile bool ready;
Thread oThread;
//Camera Declarations
CameraMan cameraMan;
Camera camera;
CameraVideoFormat videoFormat;
//Neurotechology Image Handlers
NleDetectionDetails details;
NleExtractionStatus extractionStatus;
NLExtractor extractor;
NImage theImage;
NMatcher matcher;
NLTemplate template;
NLTemplate compressed;
NGrayscaleImage grayscale;
public Form1()
{
InitializeComponent();
//Initialize Thread
oThread = new Thread(new ThreadStart(UpdateLiveImage));
imagesDB.openDB();
//Camera Declarations
cameraMan = new CameraMan(null);
camera = cameraMan.Cameras[0];
videoFormat = camera.VideoFormat;
//Extractor
extractor = new NLExtractor();
//Matcher
matcher = new NMatcher();
//Center Picture in Picturebox
pbFace2.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
//Populate Database Preview Combo Box
imagesDB.openDB();
imagesDB.fillCB(cbRecall);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
if (oThread.IsAlive)
{
//oThread.Resume();
}
else
{
oThread.Start();
btTakePic.Visible = true;
btExtract.Visible = true;
btMatch.Visible = true;
//Set Cursor to Text Box First Name
tbFirstName.TabIndex = 0;
}
tbStatus.Text = "Your Video is live!";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
pbFace2.Image = theImage.ToBitmap();
btIdentify.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
public void cbRecall_SelectedIndexChanged(object sender, EventArgs e)
{
int picID;
picID = (int)cbRecall.SelectedValue;
Image picSent = imagesDB.getPic(picID);
pbFace2.Image = picSent;
}
public void UpdateLiveImage()
{
ready = false;
camera.StartCapturing();
while (!ready)
{
theImage = camera.GetCurrentFrame();
pbFace1.Image = theImage.ToBitmap();
}
}
public void requestStop()
{
ready = false;
}
private void button2_Click(object sender, EventArgs e)
{
}
private void btExtract_Click(object sender, EventArgs e)
{
if (tbFirstName.Text.Length > 0)
{
if (imagesDB.validateFaceID(tbFirstName.Text) == true)
{
try
{
pbFace2.Image = theImage.ToBitmap();
sendFeatures(theImage);
tbFirstName.ResetText();
btIdentify.Visible = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
else
{
MessageBox.Show("Already in the Database", "Database:");
}
}
else
{
MessageBox.Show("Please Enter a Name", "Need Name:");
}
}
void sendFeatures(NImage image)
{
try
{
//convert image to grayscale
grayscale = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, image); //NImage.FromImage(NPixelFormat.Grayscale, 0, pbFace2);
template = extractor.Extract(grayscale, out details, out extractionStatus);
if (details.FaceAvailable)
{
tbStatus.AppendText("\nFound Face...");
}
if (details.EyesAvailable)
{
tbStatus.AppendText("\nFound Eyes...");
}
if (extractionStatus != NleExtractionStatus.TemplateCreated)
{
tbStatus.AppendText("Face Template Extraction Failed! Dang....");
return;
}
compressed = extractor.Compress(template);
if (compressed == null)
{
MessageBox.Show("Face Template compression failed!", "Template Failure");
return;
}
imagesDB.insertPicDB(compressed, tbFirstName.Text, pbFace2, DateTime.Now);
imagesDB.fillCB(cbRecall);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void btMatch_Click(object sender, EventArgs e)
{
identifyStreamingFeatures();
}
void identifyFeatures()
{
Bitmap myBitmap = new Bitmap(pbFace2.Image);
NImage myImage = NImage.FromBitmap(myBitmap);
NLExtractor extractor1 = new NLExtractor();
NleDetectionDetails detaills1;
NleExtractionStatus extractionStatus1;
NGrayscaleImage grayscale1 = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, myImage);
NLTemplate template1 = extractor.Extract(grayscale1, out detaills1, out extractionStatus1);
try
{
NMatcher matcher = new NMatcher();
matcher.IdentifyStart(template1.Save());
OleDbDataReader myReader = imagesDB.identifyDBSearch();
byte[] image;
int offset = 0;
tbStatus.SelectionColor = Color.Black;
tbStatus.AppendText("\n\bIdentifying Features:\b");
while (myReader.Read())
{
long fieldSize = myReader.GetBytes(0, 0, null, 0, 0);
image = new byte[fieldSize];
myReader.GetBytes(0, offset, image, 0, (int)fieldSize);
double score = matcher.IdentifyNext(image);
if (score > 50.0)
{
tbStatus.SelectionColor = Color.DarkBlue;
tbStatus.AppendText("\n " + myReader[1].ToString() + " was a successful match with a SCORE of " + score.ToString() + " Match");
}
else
{
//tbStatus.AppendText("\nFailed to match " + myReader[1].ToString() + " with the image and a score of " + score.ToString());
}
}
myReader.Close();
matcher.IdentifyEnd();
tbStatus.AppendText("\nEnd of Database Search");
tbStatus.Focus();
tbStatus.SelectionStart = tbStatus.Text.Length;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void identifyStreamingFeatures()
{
NLExtractor extractor1 = new NLExtractor();
NleDetectionDetails detaills1;
NleExtractionStatus extractionStatus1;
NGrayscaleImage grayscale1 = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, theImage);
NLTemplate template1 = extractor.Extract(grayscale1, out detaills1, out extractionStatus1);
try
{
NMatcher matcher = new NMatcher();
matcher.IdentifyStart(template1.Save());
OleDbDataReader myReader = imagesDB.identifyDBSearch();
byte[] image;
int offset = 0;
tbStatus.SelectionColor = Color.Black;
tbStatus.AppendText("\n\bLive Identifying Features:\b");
while (myReader.Read())
{
long fieldSize = myReader.GetBytes(0, 0, null, 0, 0);
image = new byte[fieldSize];
myReader.GetBytes(0, offset, image, 0, (int)fieldSize);
double score = matcher.IdentifyNext(image);
if (score > 50.0)
{
tbStatus.SelectionColor = Color.DarkBlue;
tbStatus.AppendText("\n " + myReader[1].ToString() + " was a successful match with a SCORE of " + score.ToString() + " Match");
}
else
{
//tbStatus.AppendText("\nFailed to match " + myReader[1].ToString() + " with the image and a score of " + score.ToString());
}
}
myReader.Close();
matcher.IdentifyEnd();
tbStatus.AppendText("\nEnd of Database Search");
tbStatus.Focus();
tbStatus.SelectionStart = tbStatus.Text.Length;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btIdentify_Click(object sender, EventArgs e)
{
identifyFeatures();
}
private void btUpload_Click(object sender, System.EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg, *.jpeg, *.gif, *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
pbFace2.Image = new Bitmap(open.FileName);
btExtract.Visible = true;
btIdentify.Visible = true;
}
else
{
}
}
catch (Exception)
{
throw new ApplicationException("Failed Loading Image");
}
}
