Skip to content

Commit

Permalink
comparing faces code is there, help me debug please <3
Browse files Browse the repository at this point in the history
  • Loading branch information
Marshh committed Jan 13, 2018
2 parents b620127 + 1f9d712 commit f9e45eb
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 26 deletions.
49 changes: 32 additions & 17 deletions Face_Array.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/python
'''
Takes a single photo and returns the matrix value of it
'''
import cv2
import numpy as np
import os

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
print(type(face_cascade))
Expand All @@ -13,26 +15,39 @@ def read_face(face_file: str)-> [[int]]:
img = cv2.imread(face_file) #load image
resized_image = cv2.resize(img, (450, 800))
gray = cv2.cvtColor(resized_image, cv2.COLOR_BGR2GRAY) #grayscale image
#print(gray)
faces = face_cascade.detectMultiScale(gray, 1.3, 5) #finding face, returns rectangles
print(faces)
f = faces[0]
x, y, w, h = f
print(x, y, w, h)
cropped = resized_image[y:y+h, x:x+w]

cv2.imshow(face_file,resized_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

cv2.imshow(face_file,cropped)
cv2.waitKey(0)
cv2.destroyAllWindows()

return cropped
if faces != ():

f = faces[0]
x, y, w, h = f
cropped = resized_image[y:y+h, x:x+w]
#
# cv2.imshow(face_file,resized_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#
# cv2.imshow(face_file,cropped)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

return cropped
else:
return ()

if __name__ == "__main__":
print(read_face("Faces/Snapchat-1025800267.jpg"))
face_list = ["Faces/Snapchat-840812430.jpg", "Faces/Snapchat-1025800267.jpg", "Faces/Snapchat-1068462290.jpg", "Faces/Snapchat-145761425.jpg", "Faces/Snapchat-1681206859.jpg", "Faces/Snapchat-78818167.jpg"]

#if Cropped_images folder is not created yet, create it
if not os.path.exists("Faces/Cropped_Images"):
os.makedirs("Faces/Cropped_Images")

for i in range(len(face_list)):
print(i)
crop = read_face(face_list[i])

#check if a face was detected and only write if it was
if crop != ():
cv2.imwrite("Faces/Cropped_Images/{}.png".format(i), crop)



Expand Down
Binary file added Faces/Cropped_Images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Faces/Cropped_Images/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Faces/Cropped_Images/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Faces/Cropped_Images/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Faces/Cropped_Images/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
External Libraries Used
</header>
<ul>
<li> python -m pip install opencv-python </li>
<li> python -m pip install opencv-contrib-python </li>
<li> python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose </li>
</ul>
21 changes: 15 additions & 6 deletions temp_webcam_cv3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/python
import cv2
import sys
import logging as log
import datetime as dt
from time import sleep

import os #ANNA's changes

###
import time
from PIL import Image
Expand All @@ -18,7 +21,7 @@
faceCascade = cv2.CascadeClassifier(cascPath)
log.basicConfig(filename='webcam.log',level=log.INFO)

video_capture = cv2.VideoCapture(0)
video_capture = cv2.VideoCapture(1)
anterior = 0

while True:
Expand All @@ -38,6 +41,12 @@
minNeighbors=5,
minSize=(30, 30)
)

# Display the resulting frame
cv2.imshow('Video', frame)

if faces == ():
continue

x1=0
y1=0
Expand All @@ -56,8 +65,6 @@
log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now()))


# Display the resulting frame
cv2.imshow('Video', frame)

###
# Ttemp = time.time()
Expand All @@ -68,19 +75,21 @@
###
Ttemp = time.time()
if Ttemp - Tstart > 0.8:
if not os.path.exists("oripics"):
os.makedirs("oripics")
cv2.imwrite("oripics\\"+str(index)+"s.jpg",frame)
box = (x1*0.97,y1*0.97,x2*1.03,y2*1.03)
im = Image.open("oripics\\"+str(index)+"s.jpg")
region = im.crop(box)
if not os.path.exists("editpics"):
os.makedirs("editpics")
region.save("editpics\\"+str(index)+"c.png","PNG")
index = index + 1
index += 1
Tstart = Ttemp

if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Display the resulting frame
cv2.imshow('Video', frame)

# When everything is done, release the capture
video_capture.release()
Expand Down
2 changes: 0 additions & 2 deletions webcam.log
Original file line number Diff line number Diff line change
Expand Up @@ -964,5 +964,3 @@ INFO:root:faces: 0 at 2018-01-12 22:49:16.966604
INFO:root:faces: 1 at 2018-01-12 22:58:43.897912
INFO:root:faces: 0 at 2018-01-12 22:58:45.011582
INFO:root:faces: 1 at 2018-01-12 22:58:45.098815
INFO:root:faces: 1 at 2018-01-13 02:33:12.620784
INFO:root:faces: 1 at 2018-01-13 02:35:18.456608

0 comments on commit f9e45eb

Please sign in to comment.