[mousetrap/gnome3-wip: 60/240] Add spike implementation of nose detection
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 60/240] Add spike implementation of nose detection
- Date: Mon, 8 Sep 2014 15:17:35 +0000 (UTC)
commit c09477f3e9e3f9ec053059636bdb70405f4ccfa6
Author: Kevin Brown <kbrown rediker com>
Date: Tue Jun 10 20:09:24 2014 -0400
Add spike implementation of nose detection
This adds a basic implementation of the nose detection using a
brute-force implementation that determines the face using a haar
cascade and then further detects the nose within the face rectangle.
This does not do any tracking and will need to be adjusted
considering the central nose point should probably not be
determined relative to the face. This is because the center of the
nose does not move much relative to the face when turning, but the
tip of the nose does.
run.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/run.py b/run.py
new file mode 100644
index 0000000..0b3eb90
--- /dev/null
+++ b/run.py
@@ -0,0 +1,72 @@
+import cv2
+import os
+import sys
+
+# Add the `src` directory to the system path
+
+PROJECT_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "src"))
+
+sys.path.append(PROJECT_PATH)
+
+from mousetrap.camera import Camera
+
+# Initialize the camera and get the frame
+
+camera = Camera()
+camera.start_camera()
+image = camera.get_image()
+
+# Convert the image to grayscale
+
+gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+
+# Import the haar cascades
+
+cascades = {
+ "face": cv2.CascadeClassifier("src/mousetrap/haars/haarcascade_frontalface_default.xml"),
+ "nose": cv2.CascadeClassifier("src/mousetrap/haars/haarcascade_mcs_nose.xml"),
+}
+
+# Detect faces using the cascade
+# Use a 1.5 scale to ensure the head is always found
+# Requiring 5 neighbors helps discard invalid faces
+
+faces = cascades["face"].detectMultiScale(gray, 1.5, 5)
+
+# Fail early if there were no faces
+
+if not len(faces):
+ sys.exit(1)
+
+# Unpack the detected face into a more readable dictionary
+
+face = {}
+face["x"], face["y"], face["width"], face["height"] = faces[0]
+
+# Get the smaller image for the detected face
+
+face["image"] = gray[face["y"]:face["y"] + face["height"],
+ face["x"]:face["x"] + face["width"]]
+
+# Detect noses using the cascade
+
+noses = cascades["nose"].detectMultiScale(face["image"], 1.3, 5)
+
+# Fail early is there are no noses
+
+if not len(noses):
+ sys.exit(1)
+
+# Unpack the nose
+
+nose = {}
+nose["x"], nose["y"], nose["width"], nose["height"] = noses[0]
+
+# Determine the central point of the nose
+# This is done relative to the face
+# It should probably be done relative to the entire picture
+
+nose["center"] = {
+ "x": (nose["x"] + nose["width"]) / 2,
+ "y": (nose["y"] + nose["height"]) / 2,
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]