Bläddra i källkod

image face recognizion with cropped output

FriaN 7 år sedan
förälder
incheckning
b65f791e86

+ 13 - 0
.idea/Face recognition.iml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/venv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TestRunnerService">
+    <option name="PROJECT_TEST_RUNNER" value="Unittests" />
+  </component>
+</module>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/Face recognition.iml" filepath="$PROJECT_DIR$/.idea/Face recognition.iml" />
+    </modules>
+  </component>
+</project>

+ 12 - 12
Main.py

@@ -5,21 +5,21 @@ face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
 
 if __name__ == "__main__":
 
-    cap = cv2.VideoCapture(0)
+    img = cv2.imread('TestFaces/will-smith.jpg')
 
-    while True:
-        ret, img = cap.read()
-        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
-        faces = face_cascade.detectMultiScale(gray, 1.3, 5)
+    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
 
-        for (x,y,w,h) in faces:
-            cv2.rectangle(img, (x,y), (x+w, y+h), (255, 0, 0), 2)
+    for (x,y,w,h) in faces:
+        cv2.rectangle(img, (x,y), (x+w, y+h), (255, 0, 0), 2)
 
 
-        cv2.imshow('img', img)
-        k = cv2.waitKey(30) & 0xff
-        if k == 27:
-            break
+    cv2.imshow('img', img)
 
-    cap.release()
+    crop_img = img[y:y+h, x:x+w]
+    cv2.imshow("cropped", crop_img)
+
+    cv2.imwrite("test-crop.jpg",crop_img)
+
+    cv2.waitKey(0)
     cv2.destroyAllWindows()

BIN
TestFaces/manuel-neuer.jpg


BIN
TestFaces/will-smith.jpg


+ 0 - 0
services/__init__.py


+ 0 - 0
services/face_recognizing_service.py