#1 Moar Pythonicz

Closed
moaz wants to merge 3 commits from MightyGNU/dev into MightyGNU/master
3 changed files with 19 additions and 30 deletions
  1. 11 17
      src/get_face.py
  2. 7 12
      src/get_features.py
  3. 1 1
      src/sql.py

+ 11 - 17
src/get_face.py

@@ -1,21 +1,18 @@
 #!/usr/bin/python2
 
-import time
-
-start = time.time()
-
 import argparse
-import cv2
 import itertools
 import os
+import time
 
-import numpy as np
-np.set_printoptions(precision=2)
-
+import cv2
+import numpy
 import openface
 
-from get_features import *
+import get_features
 
+start = time.time()
+numpy.set_printoptions(precision=2)
 align = openface.AlignDlib("shape_predictor_68_face_landmarks.dat")
 
 def get_faces(imgPath):
@@ -30,20 +27,17 @@ def get_faces(imgPath):
     start = time.time()
     bb = align.getAllFaceBoundingBoxes(rgb_img)
 
-    iter = 0
-
-    for img in bb:
-        iter += 1
+    for iter, img in enumerate(bb):
         x1 = abs(img.tl_corner().x)
         y1 = abs(img.tl_corner().y)
         x2 = abs(img.br_corner().x)
         y2 = abs(img.br_corner().y)
-        print(x1,x2,y1,y2)
+        print(x1, x2, y1, y2)
         crop_img = bgr_img[y1:y2, x1:x2]
-        cv2.imwrite("face"+str(iter)+".png",crop_img)
-        get_features(rgb_img,img)
+        cv2.imwrite("face{}.png".format(iter), crop_img)
+        get_features.get_features(rgb_img, img)
 
 parser = argparse.ArgumentParser()
 parser.add_argument('img', type=str, help="Input image.")
 args = parser.parse_args()
-get_faces(args.img)
+get_faces(args.img)

+ 7 - 12
src/get_features.py

@@ -1,24 +1,18 @@
 #!/usr/bin/python2
 
-import time
-
-start = time.time()
-
 import argparse
-import cv2
 import itertools
 import os
+import time
 
-import numpy as np
-np.set_printoptions(precision=2)
-
+import cv2
+import numpy
 import openface
 
-align = openface.AlignDlib("shape_predictor_68_face_landmarks.dat")
-
+numpy.set_printoptions(precision=2)
 net = openface.TorchNeuralNet("nn4.small2.v1.t7", 96)
 
-def get_features(img,bb):
+def get_features(img, bb):
     start = time.time()
     alignedFace = align.align(96, img, bb,
                               landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
@@ -31,5 +25,6 @@ def get_features(img,bb):
     print("  + OpenFace forward pass took {} seconds.".format(time.time() - start))
     print("Representation:")
     print(rep)
-    print("-----\n")
+    print("-----")
+    print()
     return rep

+ 1 - 1
src/sql.py

@@ -10,4 +10,4 @@ mydb = mysql.connector.connect(
 )
 
 def add_face(face, x,y,w,h, url):
-	cursor.execute("INSERT INTO test VALUE (?,?,?,?,?,?)", face.tobytes(), x,y,w,h, url)
+	cursor.execute("INSERT INTO test VALUE (?,?,?,?,?,?)", (face.tobytes(), x,y,w,h, url))