[mousetrap] Adding missed files
- From: Flavio Percoco <flaper src gnome org>
- To: svn-commits-list gnome org
- Subject: [mousetrap] Adding missed files
- Date: Tue, 23 Jun 2009 17:54:15 -0400 (EDT)
commit d099fab45e6b8c5aa9230df02422b3f6c38574ac
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date: Sun Jun 21 23:46:12 2009 +0200
Adding missed files
dev_tools/idm_example.py | 141 +++++++++++++++++++++++
src/mousetrap/addons/.cpu_control.py.swp | Bin 0 -> 4096 bytes
src/mousetrap/addons/Makefile.am | 10 ++
src/mousetrap/addons/cpu.py | 49 ++++++++
src/mousetrap/addons/handler.py | 86 ++++++++++++++
src/ocvfw/idm/EyeLocatorASEF128x128.fel | Bin 0 -> 131230 bytes
src/ocvfw/idm/eyes.py | 183 ++++++++++++++++++++++++++++++
7 files changed, 469 insertions(+), 0 deletions(-)
---
diff --git a/dev_tools/idm_example.py b/dev_tools/idm_example.py
new file mode 100644
index 0000000..375afd3
--- /dev/null
+++ b/dev_tools/idm_example.py
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+
+# Ocvfw
+#
+# Copyright 2009 Flavio Percoco Premoli
+#
+# This file is part of Ocvfw.
+#
+# Ocvfw is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License v2 as published
+# by the Free Software Foundation.
+#
+# Ocvfw is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ocvfw. If not, see <http://www.gnu.org/licenses/>>.
+
+
+"""Forehead IDM"""
+
+__id__ = "$Id$"
+__version__ = "$Revision$"
+__date__ = "$Date$"
+__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
+__license__ = "GPLv2"
+
+import ocvfw.commons as commons
+from ocvfw.dev.camera import Camera, Capture, Point
+
+# IDM's Information
+# a_name: IDM's name
+# This is used by the settings gui to identify the idm
+# a_description: IDM's Description
+# a_settings: Possible settings needed by the idm. For Example: { 'var_name' : { 'value' : default_value}, 'var_name2' : { 'value' : default_value} }
+a_name = "IDM Name"
+a_description = "Forehead point tracker based on LK Algorithm"
+a_settings = { 'speed' : {"value":2}}
+
+class Module(object):
+ """
+ This is the IDM's Main class, called by mousetrap.py in the load process.
+ """
+
+ def __init__(self, controller, stgs = {}):
+ """
+ IDM's init function.
+
+ Arguments:
+ - self: The main object pointer.
+ - controller: mousetrap main class pointer. This is passed by MouseTrap's controller (mousetrap.py) when loaded.
+ - stgs: Possible settings loaded from the user's settings file. If there aren't settings the IDM will use the a_settings dict.
+ """
+
+ # This will init the Camera class.
+ # This class is used to handle the camera device.
+ Camera.init()
+
+ # Controller instance
+ self.ctr = controller
+
+ # Capture instance
+ # The capture is the object containing the image
+ # and all the possible methods to modify it.
+ self.cap = None
+
+ # IDM's Settings dict
+ self.stgs = stgs
+
+ # Prepares the IDM using the settings.
+ self.prepare_config()
+
+ def prepare_config(self):
+ """
+ Prepares the IDM using the settings
+
+ Arguments:
+ - self: The main object pointer
+ """
+ global a_settings
+
+ # If the dict is empty then
+ # use the default settings defined in a_settings
+ if not self.stgs:
+ self.stgs = a_settings
+
+ # For each key do something if required by the module
+ for key in self.stgs:
+ pass
+
+ def set_capture(self, cam):
+ """
+ Initialize the capture and sets the main settings.
+
+ Arguments:
+ - self: The main object pointer
+ - cam: The camera device index. For Example: 0 = /dev/video0, 1 = /dev/video1
+ """
+
+ # Starts the Capture using the async method.
+ # This means that self.cap.sync() wont be called periodically
+ # by the idm because the Capture syncs the image asynchronously (See dev/camera.py)
+ self.cap = Capture(async=True, idx=cam)
+
+ # This sets the final image default color to rgb. The default color is bgr.
+ self.cap.change(color="rgb")
+
+ def get_image(self):
+ """
+ Gets the last queried and formated image.
+ Function used by the mousetrap/ui/main.py
+ to get the output image
+
+ Arguments:
+ - self: The main object pointer
+
+ returns self.cap.resize(200, 160, True)
+ """
+
+ # Calls the resize method passing the new with, height
+ # specifying that the new image has to be a copy of the original
+ # so, self.cap.resize will copy the original instead of modifying it.
+ return self.cap.resize(200, 160, True)
+
+ def get_pointer(self):
+ """
+ Returns the new MousePosition.
+ Function used to pass the Mouse Pointer position
+ to the Scripts.
+
+ Arguments:
+ - self: The main object pointer
+ """
+
+ # The return value has to be a Point() type object
+ # Following the forehad IDM, The return is self.cap.forehead
+ # which is created in the get_forehead function as an attribute
+ # of self.cap
+ return self.cap.pointer
diff --git a/src/mousetrap/addons/.cpu_control.py.swp b/src/mousetrap/addons/.cpu_control.py.swp
new file mode 100644
index 0000000..46ab8e7
Binary files /dev/null and b/src/mousetrap/addons/.cpu_control.py.swp differ
diff --git a/src/mousetrap/addons/Makefile.am b/src/mousetrap/addons/Makefile.am
new file mode 100755
index 0000000..8e41573
--- /dev/null
+++ b/src/mousetrap/addons/Makefile.am
@@ -0,0 +1,10 @@
+SUBDIRS = scripts
+
+mousetrap_pathdir=$(pyexecdir)
+
+mousetrap_python_PYTHON = \
+ handler.py \
+ cpu.py \
+ __init__.py
+
+mousetrap_pythondir=$(pyexecdir)/mousetrap/addons
diff --git a/src/mousetrap/addons/__init__.py b/src/mousetrap/addons/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/mousetrap/addons/cpu.py b/src/mousetrap/addons/cpu.py
new file mode 100644
index 0000000..7c59384
--- /dev/null
+++ b/src/mousetrap/addons/cpu.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+# MouseTrap
+#
+# Copyright 2009 Flavio Percoco Premoli
+#
+# This file is part of mouseTrap.
+#
+# MouseTrap is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License v2 as published
+# by the Free Software Foundation.
+#
+# mouseTrap is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mouseTrap. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import gobject
+import mousetrap.environment as env
+
+from subprocess import Popen, PIPE
+from mousetrap.addons.handler import AddonsBase
+
+a_name = "CPU"
+a_description = "Checks the CPU % usage"
+a_settings = {}
+
+class Addon(AddonsBase):
+
+ def __init__(self, controller):
+ AddonsBase.__init__(self, controller)
+
+ gobject.timeout_add(1000, self.check_cpu)
+
+ def check_cpu(self):
+ """
+ Checks the CPU usage.
+
+ Arguments:
+ - self: The main object pointer.
+ """
+ cpu = (Popen("ps -e -o pcpu,pid | grep %s" % str(env.pid), shell=True, stdout=PIPE).stdout).read().strip().split(" ")[0]
+
+ self.statusbar_message("CPU: %s" % cpu)
+ return True
diff --git a/src/mousetrap/addons/handler.py b/src/mousetrap/addons/handler.py
new file mode 100644
index 0000000..4078995
--- /dev/null
+++ b/src/mousetrap/addons/handler.py
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+
+# MouseTrap
+#
+# Copyright 2009 Flavio Percoco Premoli
+#
+# This file is part of mouseTrap.
+#
+# MouseTrap is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License v2 as published
+# by the Free Software Foundation.
+#
+# mouseTrap is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mouseTrap. If not, see <http://www.gnu.org/licenses/>.
+
+import os,re
+
+class AddonsHandler(object):
+
+ def __init__(self, controller):
+ """
+ This is the AddonsHandler init function
+
+ Arguments:
+ - self: The main object pointer.
+ - controller: The mousetrap's controller.
+ """
+
+ self.ctr = controller
+
+ def get_addons_list(self):
+ """
+ Checks the addons folder and gets the
+ list of present addons.
+
+ Arguments:
+ - self: The main object pointer.
+ """
+
+ reg = re.compile(r'([A-Za-z0-9]+)\.py$', re.DOTALL)
+ dirname = os.path.dirname(__file__)
+ return [ mod[0] for mod in [ reg.findall(f) for f in os.listdir("%s/" % dirname) if "handler" not in f] if mod ]
+
+ def get_addon_inf(self, addon):
+ """
+ Gets basic information (Name, Description, Settings)
+
+ Arguments:
+ - self: The main object pointer.
+ - addon: The addon to explore.
+ """
+ tmp = __import__("mousetrap.addons.%s" % addon,
+ globals(),
+ locals(),
+ [''])
+
+ return { "name" : tmp.a_name, "dsc" : tmp.a_description, "stgs" : tmp.a_settings}
+
+class AddonsBase(object):
+
+ def __init__(self, controller):
+ """
+ This is the AddonsBase init function
+
+ Arguments:
+ - self: The main object pointer.
+ - controller: The mousetrap's controller.
+ """
+
+ self.ctr = controller
+ self.itf = self.ctr.itf
+
+ def statusbar_message(self, msg):
+ """
+ Writes a message in the statusbar
+
+ Arguments:
+ - self: The main object pointer.
+ - msg: The message.
+ """
+ self.itf.statusbar.push(self.itf.statusbar_id, msg)
diff --git a/src/ocvfw/idm/EyeLocatorASEF128x128.fel b/src/ocvfw/idm/EyeLocatorASEF128x128.fel
new file mode 100644
index 0000000..208644c
Binary files /dev/null and b/src/ocvfw/idm/EyeLocatorASEF128x128.fel differ
diff --git a/src/ocvfw/idm/eyes.py b/src/ocvfw/idm/eyes.py
new file mode 100644
index 0000000..6dc7662
--- /dev/null
+++ b/src/ocvfw/idm/eyes.py
@@ -0,0 +1,183 @@
+# -*- coding: utf-8 -*-
+
+# Ocvfw
+#
+# Copyright 2009 Flavio Percoco Premoli
+#
+# This file is part of Ocvfw.
+#
+# Ocvfw is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License v2 as published
+# by the Free Software Foundation.
+#
+# Ocvfw is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ocvfw. If not, see <http://www.gnu.org/licenses/>>.
+
+
+"""Forehead IDM"""
+
+__id__ = "$Id$"
+__version__ = "$Revision$"
+__date__ = "$Date$"
+__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
+__license__ = "GPLv2"
+
+import pyvision as pv
+import ocvfw.commons as commons
+from ocvfw.dev.camera import Camera, Capture, Point
+from pyvision.face.FilterEyeLocator import loadFilterEyeLocator as eye_locator
+
+from opencv import cv
+
+a_name = "Eyes"
+a_description = "Eyes point tracker using pyvision"
+a_settings = { }
+
+FEL_NAME = "/home/flaper87/MouseTrap/src/ocvfw/idm/EyeLocatorASEF128x128.fel"
+
+class Module(object):
+ """
+ This is the IDM's Main class, called by mousetrap.py in the load process.
+ """
+
+ def __init__(self, controller, stgs = {}):
+ """
+ IDM's init function.
+
+ Arguments:
+ - self: The main object pointer.
+ - controller: mousetrap main class pointer. This is passed by MouseTrap's controller (mousetrap.py) when loaded.
+ - stgs: Possible settings loaded from the user's settings file. If there aren't settings the IDM will use the a_settings dict.
+ """
+ Camera.init()
+
+ self.img = None
+ self.ctr = controller
+ self.cap = None
+ self.stgs = stgs
+
+ ##############################
+ # MOTION RELATED VARIABLES #
+ ##############################
+
+ self.fel = eye_locator(FEL_NAME)
+
+ ##############################
+ # ACTION POINTS #
+ ##############################
+ self.mpPointer = None
+
+ ##############################
+ # CLICK RELATED VARIABLES #
+ ##############################
+
+ self.isMoving = False
+
+ self.prepare_config()
+
+ def prepare_config(self):
+ """
+ Prepares the IDM using the settings
+
+ Arguments:
+ - self: The main object pointer
+ """
+ global a_settings
+
+ for key in self.stgs:
+ pass
+
+ def set_capture(self, cam):
+ """
+ Initialize the capture and sets the main settings.
+
+ Arguments:
+ - self: The main object pointer
+ - cam: The camera device index. For Example: 0 = /dev/video0, 1 = /dev/video1
+ """
+ self.cap = Capture(async=False, idx=cam)
+ self.cap.change(color="rgb")
+
+ def calc_motion(self):
+ if not hasattr(self.cap, "forehead"):
+ self.get_forehead()
+
+ def get_image(self):
+ """
+ Sets the forehead point if needed and returns the formated image.
+
+ Arguments:
+ - self: The main object pointer
+
+ returns self.cap.image()
+ """
+ self.cap.sync()
+ if not hasattr(self.cap, "leye") or not hasattr(self.cap, "reye"):
+ self.get_eye()
+
+ return self.cap.resize(200, 160, True)
+
+ def get_pointer(self):
+ """
+ Returns the new MousePosition
+
+ Arguments:
+ - self: The main object pointer
+ """
+
+ return True
+
+ def get_eye(self):
+ eyes = False
+
+ face = self.cap.get_area(commons.haar_cds['Face'])
+
+ if face:
+ cvtile = cv.cvCreateMat(128,128,cv.CV_8UC3)
+ bwtile = cv.cvCreateMat(128,128,cv.CV_8U)
+ areas = [ (pt[1].x - pt[0].x)*(pt[1].y - pt[0].y) for pt in face ]
+ startF = face[areas.index(max(areas))][0]
+ endF = face[areas.index(max(areas))][1]
+ facerect = self.cap.rect(startF.x, startF.y, endF.x - startF.x, endF.y - startF.y)
+
+ if not facerect:
+ return
+
+ cv.cvResize(facerect, cvtile)
+
+ cv.cvCvtColor( cvtile, bwtile, cv.CV_BGR2GRAY )
+
+ leye,reye,lcp,rcp = self.fel.locateEyes(bwtile)
+ leye = pv.Point(leye)
+ reye = pv.Point(reye)
+
+ leye_x = int((float(leye.X())*facerect.width/cvtile.width) + startF.x)
+ leye_y = int((float(leye.Y())*facerect.height/cvtile.height) + startF.y)
+
+ reye_x = int((float(reye.X())*facerect.width/cvtile.width) + startF.x)
+ reye_y = int((float(reye.Y())*facerect.height/cvtile.height) + startF.y)
+
+ eye_rect = { "startX" : leye_x - 5,
+ "startY" : leye_y - 5,
+ "endX" : leye_x + 5,
+ "endY" : leye_y + 5}
+
+ #self.cap.image(self.cap.rect(leye_x - 5, leye_y - 5, 20, 20))
+
+ if not hasattr(self.cap, "leye"):
+ self.cap.add( Point("point", "leye", [int(leye_x), int(leye_y)], parent=self.cap, follow=True) )
+ else:
+ self.cap.add( Point("point", "reye", [int(reye_x), int(reye_y)], parent=self.cap, follow=True) )
+
+ # Shows the face rectangle
+ #self.cap.add( Graphic("rect", "Face", ( startF.x, startF.y ), (endF.x, endF.y), parent=self.cap) )
+
+
+ self.foreheadOrig = None
+
+ return False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]