NLview

General information about Neurotechnology and its software

NLview

Postby sporkz101 » Mar 06, 2010 09:54

Hello!

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");
            }
        }
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 08, 2010 13:21

Hello,

if you would like you can use a PictureBox for live view with face detection box, but in this case you shoould to develop the face detection box showing on the PictureBox.

For .Net is NLView available, which needs to get the detection details and the face box will be shown on it automatically. Samples and some tutorials shows how to use the NLView (i.e. DetectFacialFeatures).
Basic steps to show the image and detection box are below:

Code: Select all
               //load the image from file or get a frame from the camera
               //load this image to NLView control
               nlView.Image = image.ToBitmap();
               // convert image to grayscale
               prvImage = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, image);
               // create an extractor
               nlView.Image = image.ToBitmap();
               //detect faces and get detection details
               NleFace[] faces = extractor.DetectFaces(image);
               NleDetectionDetails[] detectionDetails = new NleDetectionDetails[faces.Length];
               for (int i = 0; i < detectionDetails.Length; i++)
               {
                  detectionDetails[i] = extractor.DetectFacialFeatures(image, faces[i]);
               }
               //assign details to NLView control
               nlView.DetectionDetails = detectionDetails;
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 08, 2010 22:33

Thank you very much! I will look at this when I get home tonight.

I have been pounding my head against the wall trying to do it. :) Will re-post with how it worked for me.

Thanks
Nick
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby sporkz101 » Mar 09, 2010 02:58

I feel bad for asking this question. When I type in "NLview." Image does not appear as an option. Do I have to call the NLView control into my MainForm.cs, or something?

Thanks
Nick
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 09, 2010 11:07

you need to add the NLView control to your form.

i.e. source code below adds the nlView to Panel control.

Code: Select all
            nlView1 = new NLView();
            nlView1.Dock = DockStyle.Fill;
            nlView1.AutoScroll = true;
            panel1.Controls.Add(nlView1);


Or you can add the Neurotec.Biometric.GUI.dll to the ToolBox of the Visual Studio and later add the control by using the ToolBox.
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 11, 2010 16:16

Hello again!

In order to perform that operation, I needed to update my .dlls from a version in the past. Unfortunatly, this broke something.

When I started this project last year in class, we could only get it working with a dumbed, down stripped down version of the sample, and I have not been able to debug the program. Make it hard to make this project.

What it broke though, is my webcam. In the past, I used the neurotec.cameras.cameraman.dll, but am now using the devicemanager.dll. Have there been changes that I need to look at to re-vamp my program in order to get the webcam working again?

THANKS!
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby sporkz101 » Mar 11, 2010 17:10

Ok, so I did find that the error is with this line:

Code: Select all
compressed = extractor.Compress(template);


I now have to figure out how to use that with the updated references.

What I did, is create this method:

Code: Select all
         
public static NLTemplate Compress(NLTemplate template, NleTemplateSize compressedTemplateSize)
        {
            compressedTemplateSize = NleTemplateSize.Large;
            return template;
       
        }


and I called this above it:
Code: Select all
NleTemplateSize EnrollTemplateSize = NleTemplateSize.Large;
//and then
compressed = Compress(template, EnrollTemplateSize);


Any suggestions on what I am doing? I want to return the compressed image with the template size, I am guessing.
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 15, 2010 13:56

Hello,

if you had moved from one version of VeriLook to another version, then for sure you will need to recompile your application by using new dlls. Also ensure, that the application is laoding correct dlls - sometimes people leave several version of products, so the application can load them from another folder - ensure that all dls are loaded form correct folder. Also you can consider to use the tutorials and samples from the SDK to see how the camera handling is made with NDeviceManager.

What regards the Compress method, it is obsolete in VeriLook 4.0, if you need to compress the template then you need to use Compress(NLTemplate template, NleTemplateSize compressedTemplateSize) method. You do not need to create your own method.

Just use it as it is shown below:

Code: Select all
compressed = extractor.Compress(template, NleTemplateSize.Large);
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 22, 2010 07:02

You guys have been soo helpful!

I am back on the Face Detection Preview though, and I know you guys are here to help with questions about the Neurotechnology stuff, not write my code, but I just cannot get over this hump.

Code: Select all
         private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                nlview1 = new NLView();
                nlview1.Dock = DockStyle.Fill;
                nlview1.AutoScroll = true;
                panel1.Controls.Add(nlview1);
               
                grayscale2 = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, theImage);

                //Setting Bitmap Image to Face Preview Control
                nlview1.Image = theImage.ToBitmap();

                NleFace[] faces = extractor.DetectFaces(grayscale2);
                NleDetectionDetails[] detectionDetails = new NleDetectionDetails[faces.Length];
                for (int i = 0; i < detectionDetails.Length; i++)
                {
                    detectionDetails[i] = extractor.DetectFacialFeatures(grayscale2, faces[i]);
                }
                nlview1.DetectionDetails = detectionDetails;   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }   
        }


Above is what I have written so far. What I am thinking is that I am not actually setting the nlview1 to go to my picturebox called pbFace1. Does anyone have any suggestions for doing this? I am currently using a webcam, and it will be grabbing 'theImage' from my webcam, and constantly displaying the Live Face Preview in the Picturebox.

Thanks ahead... :)
Nick
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 22, 2010 14:50

Hi Nick,

actually I am not get the idea what you want to do. If you explain what you want to do, then I will try to help you.
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 22, 2010 15:42

What I am trying to do, is activate the face detection preview for my program. I have been looking at the sample and the tutorial for a while, and haven't been able to quite get it yet.

Currently, the way it is set up, I have a button on my gui, which when it is pressed, should display the green box around face and line across eyes. Now that I think about it, I should most likely make that a function, and call it continually. I am pretty sure though that I am not setting the NLView control to display on the picturebox though as well...

So, what I am thinking I need help with is:
--figuring where to call the function,
--How to set the nlview to display the control on the picturebox

Is that a bit more clarity?
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 22, 2010 15:58

Hello,

why you want to use a PictureBox, while the NLview is possible to show captured frames?
In this case you pass captured images to NLView and it will show them. if you will need to show detection details, then you will need to pass detection details to NLView.

In case you need to show the frames continuosly, then you should pass the image to NLView each time you capture it from the webcam.
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 22, 2010 16:10

Ok,

You are right. I do have NImage theImage which is continually grabbing and image, and tossing it into the picturebox.

Code: Select all
        public void UpdateLiveImage()
        {
            ready = false;

            try
            {
                camera.StartCapturing();
                while (!ready)
                {
                    theImage = camera.GetCurrentFrame();
                    pbFace1.Image = theImage.ToBitmap();
                }
            }


I am using a picturebox over an actual nlview box because I could find no mention in the documentation on how to create an nlview box from the toolbox, and it honestly would be too much work in my opinion to switch over the entire project to that now, unless I had to in order to do this...

Now, I already do pass 'theImage' into the nlview. Is there something else I should be doing to draw the box on the screen?
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 23, 2010 09:32

Hello,

to add the NLView into the Visual Studio Toolbox you need to:

1. Right Click on the toolbox area.
2. Select "Choose items"
3. Browse for Neurotec.Biometrics.Gui.dll
4. Select "NLView" and press "OK"

After these steps NLView component will apear int he toolbox, so you will be able to drag and drop this component on your form.

If the NLView component usage is not acceptible at this stage of your development, due to big refactoring job load, and you are planing to use the PictureBox, but want to display the detection details on the PictureBox, then you will need to develop a detection details drawing on the PictureBox by yourself.
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania

Re: NLview

Postby sporkz101 » Mar 23, 2010 18:09

Ok! I got the message. :)

I started a new project, and I an going to re-engineer my project, starting with the Face Detection Preview.

I am getting an error though. :) I start the application, and I can actually see the face detection preview!!! BUT I see a red box for a few seconds, and then my nlview box goes grey with a big X through it. :(

Code: Select all

            //Start Thread
            oThread = new Thread(new ThreadStart(updateLiveImage));

            extractor = new NLExtractor();


        public void updateLiveImage()
        {
            bool ready = false;
            try
            {
                    camera.StartCapturing();
                    while (!ready)
                    {
                        theImage = camera.GetCurrentFrame();
                        Bitmap bm = theImage.ToBitmap();
                        myVideoControl.Image = new Bitmap(bm);

                        previewFace(theImage);
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void previewFace(NImage theImage)
        {
            try
            {
                grayscale = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, theImage);
                //Create an Extractor
                myVideoControl.Image = theImage.ToBitmap();
                extractor.MaxRecordsPerTemplate = 1;
                NleFace[] faces = extractor.DetectFaces(grayscale);
                NleDetectionDetails[] detectionDetails = new NleDetectionDetails[faces.Length];
                for (int i = 0; i < detectionDetails.Length; i++)
                {
                    detectionDetails[i] = extractor.DetectFacialFeatures(grayscale, faces[i]);
                }
                myVideoControl.DetectionDetails = detectionDetails;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            IList<string> licenses;
            licenses = new List<string>(new string[] { "FacesExtractor", "FacesMatcher" });

            try
            {
                Utils.ObtainLicenses(licenses);
            }
            catch (NotActivatedException ex)
            {
                MessageBox.Show(ex.Message);
            }
            try
            {
                oThread.Start();
               
            }
            catch (NeurotecException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}



Do you see what I might be doing wrong?

Thanks!
sporkz101
 
Posts: 9
Joined: Mar 05, 2010 18:52

Re: NLview

Postby Martynas » Mar 24, 2010 09:28

Hi,

can you send your test application source code to support@neurotechnology.com with detailed description of the issue. We would like to run it on our side, to see what is wrong.
Best regards,

Martynas
Support Manager
Neurotechnology
Martynas
Neurotechnology
 
Posts: 496
Joined: Sep 19, 2008 11:02
Location: Vilnius, Lithuania


Return to Public

Who is online

Users browsing this forum: No registered users and 2 guests