image dectection #25
thenishreddy
started this conversation in
General
Replies: 1 comment
-
|
Please remove all the stuff other then the code and repost it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
----------- FUNCTION TO READ THE FILE AND ADD THE NAMES AND IDs IN TO TUPLES
import cv2
import math
import time
now_time = time.clock()
face = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
glass_cas = cv2.CascadeClassifier('Haar/haarcascade_eye_tree_eyeglasses.xml')
WHITE = [255, 255, 255]
def FileRead():
Info = open("Names.txt", "r") # Open th text file in readmode
NAME = [] # The tuple to store Names
while (True): # Read all the lines in the file and store them in two tuples
Line = Info.readline()
if Line == '':
break
NAME.append (Line.split(",")[1].rstrip())
Names = FileRead() # Run the above Function to get the ID and Names Tuple
------------------- FUNCTION TO FIND THE NAME -----------------------------------------------------------
def ID2Name(ID, conf):
if ID > 0:
NameString = "Name: " + Names[ID-1] + " Distance: " + (str(round(conf)) ) # Find the Name using the index of the ID
else:
NameString = " Face Not Recognised " # Find the Name using the index of the ID
------------------- THIS FUNCTION READ THE FILE AND ADD THE NAME TO THE END OF THE FILE -----------------
def AddName():
Name = raw_input('Enter Your Name ')
Info = open("Names.txt", "r+")
ID = ((sum(1 for line in Info))+1)
Info.write(str(ID) + "," + Name + "\n")
print ("Name Stored in " + str(ID))
Info.close()
return ID
------------------- DRAW THE BOX AROUND THE FACE, ID and CONFIDENCE -------------------------------------
def DispID(x, y, w, h, NAME, Image):
------------------------------------ THE DRAWING OF THE BOX AND ID --------------------------------------
def draw_box(Image, x, y, w, h):
cv2.line(Image, (x, y), (x + (w/5) ,y), WHITE, 1)
cv2.line(Image, (x+((w/5)4), y), (x+w, y), WHITE, 1)
cv2.line(Image, (x, y), (x, y+(h/5)), WHITE, 1)
cv2.line(Image, (x+w, y), (x+w, y+(h/5)), WHITE, 1)
cv2.line(Image, (x, (y+(h/54))), (x, y+h), WHITE, 1)
cv2.line(Image, (x, (y+h)), (x + (w/5) ,y+h), WHITE, 1)
cv2.line(Image, (x+((w/5)4), y+h), (x + w, y + h), WHITE, 1)
cv2.line(Image, (x+w, (y+(h/54))), (x+w, y+h), WHITE, 1)
--------------- SECOND ID BOX ----------------------
def DispID2(x, y, w, h, NAME, Image):
--------------------------------- THE POSITION OF THE ID BOX -------------------------------------------------
------------------------------------ THE DRAWING OF THE BOX AND ID --------------------------------------
--------------- THIRD ID BOX ----------------------
def DispID3(x, y, w, h, NAME, Image):
--------------------------------- THE POSITION OF THE ID BOX -------------------------------------------------
------------------------------------ THE DRAWING OF THE BOX AND ID --------------------------------------
def DrawBox(Image, x, y, w, h):
cv2.rectangle(Image, (x, y), (x + w, y + h), (255, 255, 255), 1) # Draw a rectangle arround the face
----------------------------- THIS FUNCTION TAKES IN SPEC CASCADE, FACE CASCADE AND AN IMAGE
------------------------- IT RETURNS A CROPPED FACE AND IF POSSIBLE STRAIGHTENS THE TILT OF THE HEAD
def DetectEyes(Image):
Theta = 0
rows, cols = Image.shape
glass = glass_cas.detectMultiScale(Image) # This ditects the eyes
for (sx, sy, sw, sh) in glass:
if glass.shape[0] == 2: # The Image should have 2 eyes
if glass[1][0] > glass[0][0]:
DY = ((glass[1][1] + glass[1][3] / 2) - (glass[0][1] + glass[0][3] / 2)) # Height diffrence between the glass
DX = ((glass[1][0] + glass[1][2] / 2) - glass[0][0] + (glass[0][2] / 2)) # Width diffrance between the glass
else:
DY = (-(glass[1][1] + glass[1][3] / 2) + (glass[0][1] + glass[0][3] / 2)) # Height diffrence between the glass
DX = (-(glass[1][0] + glass[1][2] / 2) + glass[0][0] + (glass[0][2] / 2)) # Width diffrance between the glass
def tell_time_passed():


print ('TIME PASSED ' + str(round(((time.perf_counter() - now_time)/60), 2)) + ' MINS')
Beta Was this translation helpful? Give feedback.
All reactions