Change language

Iris Position Estimation Python part 2| MediaPipe | Opencv 2022

Iris Position Estimation Python part 2| MediaPipe | Opencv 2022

hi Im Asadullah from AiPile today Im just  going to show you that how can we estimate the iris position uh since i have created already  created a complete video tutorial on the iris tracking so here we are going to simply estimate  the irs position since there are there are lots of guys simply text me on the instagram that  uh how can we estimate the position of irs so because of that im just going to create a  video here uh since ive just interrupted the augmented reality course because there was not  not enough views available or there was not much interest in that particular video series so i just  abandoned this for for time being uh i will create a complete video tutorial where i will i will  show you that how can we estimate the distance from the irs or simply sorry to from the  roku marker to the camera which is far more accurate than the previous techniques  i will show you that in the future as well so before that uh ive just already created  a complete video tutorial where i just show you that how can we track the irs so  let me run this for python main dot by so im just going to show you that uh in this  video that video tutorial we have created this particular one so we have simply estimating the  iris position so obsessively tracking the irs you can see this is working really fine you can see  this so thats very much simple and easy stuff now we have to go over to the irs position  estimation so im just going to open this code here so visual studio code so simply its  open up on my next uh window so let me go into the same mode so before that i have just have  to simply explain the algorithm so for that so first of all uh here you have the iris center  and then you have this uh two points like you here we can call this the leftmost point then you have  the rightmost point here you can see this so what we have to do simply find the distance between  these points like from the left most point to the right most point and then we have to find the  distance from this particular iris center and to the uh left rightmost point so that we can simply  find the ratio of both of these distance and then we will be able to estimate that as you can see  the distance so this pretty much simple algorithm so now coding part first of all im just going to  show you the previous code uh that we have already written in the previous video tutorial simply we  have simply tracked the irs so here you have this uh simply first of all you have to switch  this these landmarks uh which is im just going to show you in the uh whenever we are  going to create create a script here so here you have this all the code so ive explained this  everything in the my previous video tutorial you can check out that as well and and then im just  going to create another another script so eyes opposition dot pi so here we are just going to  copy this from this entire code from here and then so yes im just going to copy this and then paste  this here so we do not need to type this type entire code here so im just going to change this  this is the simply we have to switch this im just going to provide the correct lane marks so you  do not need to worry about that right and then you have this left okay so let me uh simply write  a few functions uh before that i need a simply lane marks here as well uh for this simply the uh  right most position in leftmost position so im just going to get grab this for both of these eyes  so im just going to copy this from another script so here you have this all the landmark so  these landmarks you will be getting from this i will provide that this one in the description as  well in the comment so you can get this as well so that would be really simple and now another thing  we need to create two functions here in order to estimate the position first of all we need  to find the uh distance so for that we need a euclidean distance function so it would  be def or sorry it would be uh sorry def so lydian so it would be euclidean distance so this is  the function and then we need uh simply uh two points so point one and then we have point so we  need to find the distance between two points so thats why we need point one and point two so  since we are going to use a numpy array so im just going to call this x1 and y1 because we are  going to get the exit wire from this particular array so it would be point one dot reveal  so we here how thats how we can get uh the get the x and y value from this so we can extract  the assembly value from the numpy array so you you have the x and y im just going to copy this  again and instead of one we have to right here instead of one im just going  to put here the multiculture and here and then you have the simply too so  this is going to work really fine now we have to find the distance so for that we need to  import the math so this math module is already available in the python so you do not need to  install this math and then its very much simple then you need here the we need to find the  distance so in case you want to know about the euclidean distance then just search  upon on the internet you will get this uh all this stuff how its going to work so it  should be distance is equal to uh simply we need to find the math from the math we need to find get  the square root so square root and then we need to get the uh distance simply the difference  between the x and y so it would be x2 minus x y x 1 so this is the difference and then  we need to square this up and then plus sorry so also y 2 minus y 1 and then we  need to find the square root of the square of the x naught square root so now we  need to find the square root of both of these values uh simply we need the sum of both of these  value and we need to find the square root again so that we will be having the distance you can  say euclidean we need to return this return this uh distance and thats pretty much simple and then  we need to find uh create another function we are which will be able to find us uh the position so  its going to return the position and the value of ratio so thats very very simple so it would  be diff eyes simply if we can say this irs posey and we need to find here this we  need center of irs so we can call this irs center and then we have the right a point and  then we have left points so left most point and right most point so it would be left point  so thats very much simple and then we need to find the distance so it would be uh you can  say thats center center to right distance so it would be distance is equal to simply euclidean  distance and then you have this simply center simply iris oh sorry iris  center then you have right point and then we also need a distance  between the we can say the left also we can say this left left point and then we need to say here  the total distance instead of this so total distance and then we have to find here ratio is equal to uh simply the  same uh the center center to right distance then we have this so we are going  to find for simply one eye it will be very fine you can uh also find this for the two eyes as  well for the example purpose im just going to show you this for the one eye you can simply call  this function again and you can find this for the uh second eye as well now it  would be simply total distance now we have the ratio uh then we have to  simply check either uh since ive already uh tested this up its working really fine so  thats why im just going to call this ratio ratio is equal to a less than or  equal to if we can say this 45 0.42 then we are going to say this here first we have  to create empty string so it will be ice irs for patient is equal to so empty string and  then we need to say iris position equal to simply uh we can say this is the right and then  we have this for if uh we so it would be l if l if and then we have this ratio ratio is greater  than sorry greater than uh you can say this 40 zero point so 0.42 and less than equal to  you can say this 50 im just going to call this uh keep the zero point of five seven so its  going to work and the iris position is equal to where is position equal to uh simply left center  sorry will be center then you have the else sorry here we have to  provide the ratio ratio issue else so now uh final will be else because we do  not need to specify the year values and then we have this we can say this uh irs position is  equal to is equal to simply left and then we need to return this value so it would be returned  so were gonna pass the iris that is position as position and then we  need to pass here the ratio this is fine really fine okay now these these are  the functions which is going to uh which are going to help us to find uh the simply uh iris position  so now another thing here uh we need simply the eyes values so first of all im just going to  uh simply use these landmarks here to find the distance so it would be really simple first of all  im just going to draw the landmark so it would be really simple we are going to use these here if  i can show you that so we are going to use this landmark so for the right eye so here here we  have this select this landmark you can see this so im just going to right here instead of  this we are going to use two probably two one and then yes instead of center we need to fi find  here the mesh points and then you have this right and im just going to keep this to white so here we are because its 2d  number array so we need split one and then you have this right instead of right we  need here the left okay its fine fine and then we need so here im just going to change this  color to probably yellow because uh yeah its green and red so it should be yellow so im  just going to run this and let me show you that so let me run this so it would be  eyes python eyes opposition estimation so here you can see this these are the  landmarks you can finally see them is a bit smaller in size so im just going to  increase the uh yeah we need to simply here minus one uh probably i just want to increase  this to three and then this one lets do three so that we its a bit visible to us and then  you have this one now let me run this again so here you can see this all landmarks being  shown here so you have the right one is the white and the left one is yellow so you can  see this is working really fine so now uh what we have to do simply we need to find  the distance so thats pretty much simple so now first we need to find the distance so that  would be really simple uh sorry we need to find the position of i so first of all we need to do  here call the iris so irs position so this is the function its going to return us two things  here first will be the uh the value value of the position of the iris so also iris for function is  equal to and then you have this simply the ratio so its really simple and then  we need to simply specify the uh values here as well so for example we  need to simply from the mesh point so we need uh simply the left right so it would be first the  center im just going to copy this you know first then you have this you can say the center center  or left not right left right and then you need and then you im just going to remove this uh  this is the mesh points and then you have them again similar one but here we need uh simply  yes right this one left and then you have this it would be simply right okay its going to work  really fine now now let me run this and simply print this value here so now we need to print  the iris position so im just going to do this here is position sorry sorry this is so we need to  change this iris im just going to call this pose since the function in the name  of the function is almost similar also were gonna call this here and then let  me run this and show you in the console as well sorry in the terminal so so here you can see this  so you can see the right you can see the left you can see the indica uh terminal its working  really fine if i am on the center you can see this so you can see its working really fine so  now im just going to do this im just going to insert up this particular one we are going  to print uh simply show the text on the screen so it would be really simple so im just going  to comment this up and what we have to do here simply cv dot output text put text and then we  need to provide here the frame frame and then we need to pass near the text so it would be f  string so im just going to pass here that uh i s pause and we need to provide here that city  the value of this one so it would be position it would be iris force and then we have this you  know im just going to provide the ratio of this so it would be simply im just going to write  the ratio of value of the particular ratio you can see this so it will be uh you can see  this im just going to provide here the ratio and thats pretty much fine now  we need to simply change this to to map so im just going to right here  the two uh decimal split place values you can see the floating point uh you  can send that we are running rounding the uh digits then we need to provide here the position where we want to place the takes so it  would be im just going to keep this to 30 by 30 so we are going to right here  and then we need to simply right here the font is face so it would be cv  dot our fonts on so plan sorry not flashy complex then then we need to provide here the font  scale so im just going to click this 1.2 probably and then you have this color so im just  going to keep this two zero 255 and zero uh the green color and then you have this thickness  to be one and you can see the cv dot line type and fine so let me run this hopefully  this will be shown over there so im just going to close this  right bar so here you can see this so here is black formatter its going to  format the code when im going to write this its going to format it correctly so thats why  you can see this pretty much readable very much make it more readable you can say that  so now let me run this here clear this terminal and then you have this  ice position hd ice position dot pi so you can see this is the is position so  currently im in the center looking at center right left series center right center so currently its working really  fine you can see this uh the position of eyes on the corner as well so thats pretty much  it from this video tutorial in case you want to ask anything then let me know in the comment  i will try to answer this so thank you so much and take care of yourself and this is for the  one of one eye probably you have to uh call this function again you can simply estimate the  position of twice as well so thats very much bye

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically