Solved

# delphi grachics, problem of the eye

Posted on 2010-11-30
387 Views
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26642735.html
This code I follow, but problem, it can't point the right position, try it.

The image that I'm testing;(it takes an 8click before it gets there, but position is still not correct.

A fix from the code will do, please.
0
Question by:systan
• 12
• 5
• 2

LVL 13

Expert Comment

Systan... I have no idea what you are asking.
You asked how to draw a line between two colours
Now you are showing us eyes.
Do you want to draw a line between two eyes?
0

LVL 14

Author Comment

yes, I use the code of ThievingSix, but didn't fix it.
0

LVL 13

Expert Comment

As ThievingSix explained, his code is for connecting 2 exact colours in an image.
Two eyes are a different problem.

Will you always be using a black and white image?
Is it possible for a single eye to show up as 2x objects?

I had an algorithm that scans a black and white image from left to right and counts the number of black images in each COLUMN and then stores them in an array of SmallInt, so you might have something like this:
00000220000000022000000

Then another algorithm will go through this array and detect the eyes by looking for the columns with the highest values. So what if you had something like this
00000123200000002310000
it would connect3 to 3
but you could also tell it to ignore consecutive values etc.

So what would separate one eye from another eye?
Well if it sees more than 2x 0's between sections of noise.
but then if your scan looks like this it would fail:
0000023002200000000000230000
0

LVL 25

Expert Comment

for those who want to know where that comes from :

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26646496.html

Finding the eyes is going to be a much tougher problem, starting from the 2 top images

I'll think tomorrow about this. I have a question though, about how you get the original image (greyscale) from any color picture, say from a webcam ? Have you Delphi code for that, or do you use some image tools application (PaintShop, PhotoShop...) ?
0

LVL 25

Assisted Solution

epasquier earned 50 total points
rfwoolf, I think you are close to what I did to detect the head frame on the other question.
The 2 images I generated are something like your array, but with greater precision, and 2D. Both approach have the same goal : try to simplify the image information, reduce the noise impact, up to a point where we can devise an algorithm to detect objects within the image.

One will have to think about this question : What makes some pixels area being recognized as "The Eyes" ?
0

LVL 14

Author Comment

I base the gray-scale on this link;
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26646496.html#34239337
and this;
ShowImage.ZIP
edge.zip

Now, we don't have to develop from c to delphi of opencv, we have experts here, that can turn the turtle to fly, lol

Ok;
Listening...

Thanks
0

LVL 13

Expert Comment

We need to cover some other ground first...
What exactly are you trying to do here?
What is the project goal?
Can we assume that the person will always have their head in the correct frame of the screen?
How intelligent does the software have to be? For example, you could have a user who puts his head far away from the camera, where his eyes will be 1 pixel each. Then you could have a user that puts their head close to the camera, then his eyes are 9 pixels each (for example). We could have an algorithm that scans through the image looking for white objects with pixels < 9 and > 2 pixels. if it finds more than 2 objects it can then have some intelligence such as looking for the 2 objects with the most similar sizes, or the 2 objects closest to the centre of the frame, or it could take an average of the size of the objects and take the 2 objects that are closest to the average etc.
You could run some tests - count the number of white pixels per eye, relative to the dimensions of the head frame.
For example, if the user is close to the camera, his/her head will be 400x 400pixels (for example) and his eyes will be 9 pixels each.
If the user is further away, and the frame is 200 x 200 pixels and you see the eyes are 4 pixels each etc...

This may be something you will have to develop by yourself, but we can provide some of the functions to read the images, and you will have to build in the intelligence.
0

LVL 13

Accepted Solution

rfwoolf earned 200 total points
Here is some thinking out loud about how to do this...

To take a black and white image and build an array of every 'white' object (ArrayWhiteObjects), every object will be an array of pixel co-ordinates.
We would start scanning the black and white image from the top left corner, and when we encounter a white pixel, we start another procedure which:
1: adds a new 'white object' to the ArrayWhiteObjects
2: Change the pixel in the black and white image to black so that it doesn't get read again.
3: 'Bleed' out from the white pixel in all 8 directions detecting another white pixel - if one is found, goto "2"
4: Finished adding a new 'white' object.

Now that we have our 'array' of white objects, we can start to detect which white objects are eyes.

Then based on the research of "EyeSize" relative to "Head-Size" we can filter out objects that are too big or to small to be eyes. In this example we will say i the frame size is 400 x 400 pixels, then the eyes should be no bigger than 9 pixels and no smaller than 2 pixels...
BiggestEyeSize := 9;
SmallestEyeSize := 2;

Now we itereate through ArrayWhiteObjects and add any matching objects to yet another array:
``````var
ArrayPotentialEyes : array of tWhiteObjects;
For i := 0 to length(ArrayWhiteObjects) do
begin
if (length(ArrayWhiteObjects[i]) < BiggestEyeSize)) and (length(ArrayWhiteObjects[i]) > SmallestEyeSize)) then
begin
Setlength(ArrayPotentialEyes, Length(ArrayPotentialEyes) + 1);
High(ArrayPotentialEyes) := ArrayWhiteObjects[i];
end;
end;
``````

Now that we have our array of potential eyes, we try to pick out the 2 objects that are most likely to be the eyes...
0

LVL 14

Author Comment

>>What is the project goal?

First, this is not a project, this is just some test, studies as a student developer
The goal here is to get the eye value or position from x and y
because if we get the x position and y position, we can balance the frame if x1<>x2 or y1<>y2

0

LVL 13

Expert Comment

So have you found a way to automatically remove the hair and end up with only the eyes like you have in these shots?
In these shots the eyes are 4 pixels each, will they always be 4 pixels each?
0

LVL 14

Author Comment

http://mc-computing.com/languages/delphi/images.html
I refer to that link, but I can't do it alone, my bad

Ok, I hope you guys understand the goal of this post.

Thanks
0

LVL 14

Author Comment

>>So have you found a way to automatically remove the hair and end up with only the eyes like you have in these shots?
NO, I haven't found the way, I just jump on this area, because when I see epasquiers answer to my other post, I think a jump on this, because if we get this method, we can go back to the result of that 4 white pixels,  the important thing is we got it working on this procedure. (if really work)
0

LVL 14

Author Comment

>>In these shots the eyes are 4 pixels each, will they always be 4 pixels each?
I don't know, its epasquiers call to answer that, seems his the master mind of that image procedure of how it got there.
0

LVL 14

Author Comment

epasquier?
>>One will have to think about this question : What makes some pixels area being recognized as "The Eyes" ?
Ok, it is recognize because they are separated in a form of 4 pixels and they are in the center.

0

LVL 14

Author Comment

Ok;
The procedure to get the eye is to get the face.!? right.
Assuming that face is colored then invert it to a film scale
Then in a film scale picture, transform it into a black and white seen, from that we can see the eye is white with 4+pixels grouped.

It's hard to explain, but, I'll try another words to define it well.  I'm not an excellent English talker.
0

LVL 14

Author Comment

http://gidesa.altervista.org/camshiftdemo.php
Delphi Rocks!

But well build our own procedure here, with the participation of Ex-Ex Delphi Experts.
0

LVL 14

Author Comment

hey guys, where are you, are we finished here?
0

LVL 14

Author Comment

We need to cover some other ground first...
What exactly are you trying to do here?
What is the project goal?
Can we assume that the person will always have their head in the correct frame of the screen?
How intelligent does the software have to be? For example, you could have a user who puts his head far away from the camera, where his eyes will be 1 pixel each. Then you could have a user that puts their head close to the camera, then his eyes are 9 pixels each (for example). We could have an algorithm that scans through the image looking for white objects with pixels < 9 and > 2 pixels. if it finds more than 2 objects it can then have some intelligence such as looking for the 2 objects with the most similar sizes, or the 2 objects closest to the centre of the frame, or it could take an average of the size of the objects and take the 2 objects that are closest to the average etc.
You could run some tests - count the number of white pixels per eye, relative to the dimensions of the head frame.
For example, if the user is close to the camera, his/her head will be 400x 400pixels (for example) and his eyes will be 9 pixels each.
If the user is further away, and the frame is 200 x 200 pixels and you see the eyes are 4 pixels each etc...

This may be something you will have to develop by yourself, but we can provide some of the functions to read the images, and you will have to build in the intelligence.

Ok;
I've read it, I'll open another post for this continuation.
As I've research so far, we have to detect the white circle  in film scale.
0

LVL 14

Author Closing Comment

Thanks

I'm only concerned about 1 persons image in the picture.
So the white circle could be detected.
0

## Featured Post

A lot of questions regard threads in Delphi. Â  One of the more specific questions is how to show progress of the thread. Â  Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to theâ€¦
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi projâ€¦
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, frâ€¦
This tutorial demonstrates a quick way of adding group price to multiple Magento products.