mousetrap r7 - in trunk: . src/mouseTrap src/mouseTrap/haarcascade src/mouseTrap/scripts/profiles
- From: flaper svn gnome org
- To: svn-commits-list gnome org
- Subject: mousetrap r7 - in trunk: . src/mouseTrap src/mouseTrap/haarcascade src/mouseTrap/scripts/profiles
- Date: Thu, 4 Sep 2008 12:04:27 +0000 (UTC)
Author: flaper
Date: Thu Sep 4 12:04:27 2008
New Revision: 7
URL: http://svn.gnome.org/viewvc/mousetrap?rev=7&view=rev
Log:
Cam Module Improvements
Removed:
trunk/src/mouseTrap/haarcascade/allmen7pos1000neg7000eye.xml
Modified:
trunk/ChangeLog
trunk/src/mouseTrap/cam.py
trunk/src/mouseTrap/mainGui.py
trunk/src/mouseTrap/mouseTrap.py
trunk/src/mouseTrap/ocvfw.py
trunk/src/mouseTrap/scripts/profiles/screenProfile.py
Modified: trunk/src/mouseTrap/cam.py
==============================================================================
--- trunk/src/mouseTrap/cam.py (original)
+++ trunk/src/mouseTrap/cam.py Thu Sep 4 12:04:27 2008
@@ -126,7 +126,7 @@
self.cmStartCamera( self.settings.inputDevIndex )
if( self.capture ):
- gobject.timeout_add(10, self._checkImg)
+ gobject.timeout_add(100, self._checkImg)
except:
debug.log( debug.MODULES, _( "Highest" ) )
@@ -146,7 +146,7 @@
#if not self.foreheadOrig and not self.forehead:
if not self.imgLKPoints["last"]:
- self._setForehead( self.cmGetHaarPoints( self.haarCds['Eyes'] ) )
+ self._setForehead( self.cmGetHaarPoints( self.haarCds['Face'] ) )
if len(self.imgLKPoints["last"]) > 0:
self.cmShowLKPoints()
@@ -169,7 +169,7 @@
return self.run
- def _setForehead( self, points ):
+ def _setForehead( self, face ):
"""
Detect the forehead point and set it.
@@ -180,11 +180,27 @@
self.cmAddMessage("Getting Forehead!!!")
- if points:
- areas = [ (pt[1].x - pt[0].x)*(pt[1].y - pt[0].y) for pt in points]
+ if face:
+ areas = [ (pt[1].x - pt[0].x)*(pt[1].y - pt[0].y) for pt in face]
- point1 = points[areas.index(max(areas))][0]
- point2 = points[areas.index(max(areas))][1]
+ startF = face[areas.index(max(areas))][0]
+ endF = face[areas.index(max(areas))][1]
+
+ #eyes = self.cmGetHaarPoints( self.haarCds['Eyes'] )
+
+ if not face:
+ return True
+
+ rec = cv.cvRect( startF.x, startF.y, endF.x - startF.x, endF.y - startF.y )
+
+ eyes = self.cmGetHaarROIPoints( self.haarCds['Eyes'], rec, (startF.x, startF.y) )
+
+ if eyes:
+ areas = [ (pt[1].x - pt[0].x)*(pt[1].y - pt[0].y) for pt in eyes ]
+ #if pt[0].x in range(startF.x, endF.x) and pt[0].y in range(startF.y, endF.y) ]
+
+ point1 = eyes[areas.index(max(areas))][0]
+ point2 = eyes[areas.index(max(areas))][1]
X = ( (point1.x + point2.x) / 2 )
Y = ( point1.y + ( (point1.y + point2.y) / 2 ) ) / 2
Modified: trunk/src/mouseTrap/mainGui.py
==============================================================================
--- trunk/src/mouseTrap/mainGui.py (original)
+++ trunk/src/mouseTrap/mainGui.py Thu Sep 4 12:04:27 2008
@@ -137,9 +137,13 @@
hBox.pack_start( showCapture, False, False )
flipButton = gtk.Button( _("Flip Image") )
- flipButton.connect("clicked", self.enaDisFlip )
+ flipButton.connect("clicked", self.recalcPoint, "flip" )
hBox.pack_start( flipButton, False, False )
+ recalcButton = gtk.Button( _("Recalc Point") )
+ recalcButton.connect("clicked", self.recalcPoint )
+ hBox.pack_start( recalcButton, False, False )
+
self.vBox.pack_end(hBox, False, False )
self.buttonsBox.show_all()
@@ -147,7 +151,7 @@
self.add(self.vBox)
self.show()
- def enaDisFlip( self, *args ):
+ def recalcPoint( self, widget, flip = ''):
"""
Enables the Flip of the Image in the X axis
@@ -157,9 +161,11 @@
- self: The main object pointer.
- *args: Widget related arguments.
"""
+
+ if flip:
+ self.settings.flipImage = not self.settings.flipImage
- self.settings.flipImage = not self.settings.flipImage
- #mouseTrap.modExec( "cam", "cmCleanLKPoints" )
+ mouseTrap.calcPoint()
def updateView( self, img ):
"""
Modified: trunk/src/mouseTrap/mouseTrap.py
==============================================================================
--- trunk/src/mouseTrap/mouseTrap.py (original)
+++ trunk/src/mouseTrap/mouseTrap.py Thu Sep 4 12:04:27 2008
@@ -228,7 +228,16 @@
except:
debug.log( debug.LOAD, _( "Highest" ) )
-
+
+def calcPoint():
+ """
+ Allow users to recalculate the forehead point
+ if needed.
+ """
+
+ if settings.startCam:
+ modules["cam"].cmCleanLKPoints()
+
# For Profiling pourpouse uncoment the next line
# The profile file will be saved in the user config folder
# as profiling.data
Modified: trunk/src/mouseTrap/ocvfw.py
==============================================================================
--- trunk/src/mouseTrap/ocvfw.py (original)
+++ trunk/src/mouseTrap/ocvfw.py Thu Sep 4 12:04:27 2008
@@ -107,6 +107,36 @@
cv.cvPoint( int((r.x+r.width)*self.imageScale), int((r.y+r.height)*self.imageScale) )] \
for r in points]
return matches
+
+ def cmGetHaarROIPoints( self, haarCascade, rect, origSize = (0,0), method = cv.CV_HAAR_DO_CANNY_PRUNING ):
+ """
+ Search for points matching the haarcascade selected.
+
+ Arguments:
+ - self: The main object pointer.
+ - haarCascade: The selected cascade.
+ - methode: The search method to use. DEFAULT: cv.CV_HAAR_DO_CANNY_PRUNING.
+
+ Returns a list with the matches.
+ """
+
+ cascade = cv.cvLoadHaarClassifierCascade( haarCascade, self.imgSize )
+
+ cv.cvClearMemStorage( self.storage )
+
+ imageROI = cv.cvGetSubRect( self.img, rect )
+
+ if cascade:
+ points = cv.cvHaarDetectObjects( imageROI, cascade, self.storage,
+ 1.2, 2, method, cv.cvSize(20,20) )
+ else:
+ debug.log( debug.ACTIONS, _( "Required" ) )
+
+ if points:
+ matches = [ [ cv.cvPoint( int(r.x+origSize[0]), int(r.y+origSize[1])), \
+ cv.cvPoint( int(r.x+r.width+origSize[0]), int(r.y+r.height+origSize[1] ))] \
+ for r in points]
+ return matches
def cmSetLKPoints( self, label, point):
"""
Modified: trunk/src/mouseTrap/scripts/profiles/screenProfile.py
==============================================================================
--- trunk/src/mouseTrap/scripts/profiles/screenProfile.py (original)
+++ trunk/src/mouseTrap/scripts/profiles/screenProfile.py Thu Sep 4 12:04:27 2008
@@ -28,6 +28,7 @@
__license__ = "GPLv2"
import gtk
+import time
import mouseTrap.events as events
import mouseTrap.environment as env
import mouseTrap.mouseTrap as mouseTrap
@@ -62,6 +63,7 @@
self.settings = mouseTrap.settings
self.gui = gui
+ self.last = time.time()
self.mpClick = [ 0, 0, 0, 0, 0, 0 ]
self._loadSettings()
@@ -113,7 +115,10 @@
events.registerMapperEvent( "screeMode", [ self.vScreen["startX"], self.vScreen["startY"] ],
[ self.vScreen["endX"], self.vScreen["endY"] ], True, ["moveMode:screen"], self._moveScreenMode, 0)
-
+
+ events.registerMapperEvent( "timeupdate", [ self.vScreen["startX"], self.vScreen["startY"] ],
+ [ self.vScreen["endX"], self.vScreen["endY"] ], False, ["moveMode:screen"], self._timeUpdate, 0)
+
def mouseClick( self, widget, event, mapper ):
"""
This is the callback function for the mouse clicks in the
@@ -166,7 +171,18 @@
self.gui.mapper.drawRectangle( context, self.mpClick[0], self.mpClick[1], self.mpClick[4], self.mpClick[5], (10, 0.8, 0.1))
else:
self.gui.mapper.drawRectangle( context, self.mpClick[2], self.mpClick[3], self.mpClick[4], self.mpClick[5], (10, 0.8, 0.1))
-
+
+ def _timeUpdate( self, *args ):
+ """
+ This function updates the self.last time so the mouse
+ pointer wont be sticked to the desktop when the mapper
+ pointer is not inside the virtual screen.
+
+ Arguments:
+ - self: The main object pointer
+ """
+ self.last = time.time()
+
def _moveScreenMode( self, *args ):
"""
Perform the movements of the pointer using the 'REAL MOUSE' mode.
@@ -176,8 +192,14 @@
"""
if not mouseTrap.getModVar( "cam", "forehead" ):
+ self.last = time.time()
return
-
+
+ diff = mouseTrap.getModVar( "cam", "foreheadDiff")
+
+ if time.time() - self.last >= 0.2 and not abs(diff.x) >= 3 and not abs(diff.y) >= 3:
+ return
+
curX, curY = mouseTrap.mice( "position" )
pointer = mouseTrap.getModVar( "cam", "mpPointer" )
@@ -190,6 +212,7 @@
(self.vScreen["height"]/2) - ( vScreenCenter[1] - pointer.y ) ])]
if not curX == newX or not curY == newY:
+ self.last = time.time()
mouseTrap.mice( "move", newX, newY )
def prefTab( self, prefGui ):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]