Esempio n. 1
0
    def get_haar_roi_points(self, haarCascade, rect, origSize=(0, 0), method=1):
        """
        Search for points matching the haarcascade selected.

        Arguments:
        - self: The main object pointer.
        - haarCascade: The selected cascade.
        - methode: The search method to use. DEFAULT: co.cv.CV_HAAR_DO_CANNY_PRUNING.

        Returns a list with the matches.
        """
        cascade = cv2.CascadeClassifier(haarCascade)
        if not cascade:
            debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" )

        #FIXME: Work around to fix when the rect is too big
        if (rect[0]+rect[2]) > self.img.width:
            rect = (rect[0], rect[1], self.img.width-rect[0],self.img.height-rect[1])
        if (rect[1]+rect[3]) > self.img.height:
            rect = (rect[0], rect[1], self.img.width-rect[0],self.img.height-rect[1])

        imageROI = self.img[rect[1]:rect[3], rect[0]:rect[2]]

        if cascade:
            points = cascade.detectMultiScale(imageROI,1.2,2,method,(20,20))
        else:
            debug.exception( "ocvfw", "The Haar Classifier Cascade load Failed (ROI)" )

        if points:
            matches = [ [ ( int(r[0][0]*origSize[0]), int(r[0][1]*origSize[1])), \
                          ( int((r[0][0]+r[0][3])+origSize[0]), int((r[0][1]+r[0][2])*origSize[1]) )] \
                          for r in points]

            debug.debug( "ocvfw", "cmGetHaarROIPoints: detected some matches" )
            return matches
Esempio n. 2
0
    def set_lkpoint(self, point):
        """
        Set a point to follow it using the L. Kallman method.

        Arguments:
        - self: The main object pointer.
        - point: A co.cv.Point Point.
        """

        cvPoint = (point.x, point.y)

        self.img_lkpoints["current"] = numpy.mat((point.x,point.y),numpy.float32)
        self.grey = numpy.asarray(self.grey[:,:])

        if numpy.all(self.img_lkpoints["current"]):
            cv2.cornerSubPix(
                self.grey,
                self.img_lkpoints["current"],
                (20, 20), (0,0),
                (cv2.TERM_CRITERIA_MAX_ITER | cv2.TERM_CRITERIA_EPS, 20, 0.03))

            point.set_opencv( cvPoint )
            self.img_lkpoints["points"].append(point)

            setattr(point.parent, point.label, point)

            if len(self.img_lkpoints["last"]) > 0:
                self.img_lkpoints["last"] = numpy.append(self.img_lkpoints["last"], self.img_lkpoints["current"][0])

            debug.debug( "ocvfw", "cmSetLKPoints: New LK Point Added" )
        else:
            self.img_lkpoints["current"] = []
Esempio n. 3
0
    def get_haar_points(self, haarCascade, method=1):
        """
        Search for points matching the haarcascade selected.

        Arguments:
        - self: The main object pointer.
        - haarCascade: The selected cascade.
        - methode: The search method to use. DEFAULT: co.cv.CV_HAAR_DO_CANNY_PRUNING.

        Returns a list with the matches.
        """

        cascade = cv2.CascadeClassifier(haarCascade)

        if not cascade:
            debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" )

        self.small_img = cv2.resize(self.img,(self.small_img.shape[0],self.small_img.shape[1]),self.small_img,0,0,cv2.INTER_LINEAR)

        points = cascade.detectMultiScale(self.small_img,1.2,2,method,(20,20))

        if numpy.any(points):
            matches = [ [ ( int(r[0]*self.imageScale), int(r[1]*self.imageScale)), \
                        ( int((r[0]+r[3])*self.imageScale), int((r[0]+r[2])*self.imageScale) )] \
                        for r in points]

            debug.debug( "ocvfw", "cmGetHaarPoints: detected some matches" )
            return matches
Esempio n. 4
0
    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.
        """
        debug.debug("mousetrap.ocvfw.idm", "Starting %s idm" % a_name)
        
        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()
        debug.info("mousetrap.ocvfw.idm", "Forhead Algorithm loaded")
Esempio n. 5
0
    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.
        """
        debug.debug("mousetrap.ocvfw.idm", "Starting %s idm" % a_name)

        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()
        debug.info("mousetrap.ocvfw.idm", "Forhead Algorithm loaded")
Esempio n. 6
0
    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.
        """

        debug.debug("mousetrap.ocvfw.idm", "Starting %s idm" % a_name)
        
        self.ctr          = controller
        self.cap          = None
        self.stgs         = stgs

        ##############################
        #  MOTION RELATED VARIABLES  #
        ##############################

        #self.step         = self.settings.getint( "mouse", "stepSpeed" )
        self.tmpl          = None

        self.timer         = None

        self.prepare_config()
        debug.info("mousetrap.ocvfw.idm", "Finger Algorithm loaded")
Esempio n. 7
0
    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.
        """

        debug.debug("mousetrap.ocvfw.idm", "Starting %s idm" % a_name)

        self.ctr          = controller
        self.cap          = None
        self.stgs         = stgs

        ##############################
        #  MOTION RELATED VARIABLES  #
        ##############################

        #self.step         = self.settings.getint( "mouse", "stepSpeed" )
        self.tmpl          = None

        self.timer         = None

        self.prepare_config()
        debug.info("mousetrap.ocvfw.idm", "Finger Algorithm loaded")
Esempio n. 8
0
    def set(self, key, value):
        """
        """
        if hasattr(self, "%s" % key):
            getattr(self, "%s" % key)(value)
            debug.debug("_ocv - set", "Changed %s value to %s" % (key, value))
            return True

        debug.debug("_ocv - set", "%s not found" % (key))
        return False
Esempio n. 9
0
    def start_camera(self, params = None):
        """
        Starts the camera capture

        Arguments:
        - params: A list with the capture properties. NOTE: Not implemented yet.
        """
        self.capture = cv2.VideoCapture(self.idx)

        debug.debug( "ocvfw", "start_camera: Camera Started" )
Esempio n. 10
0
    def cap_template(self):
        """
        Captures the template

        Arguments:
        - self: The main object pointer.
        """

        debug.debug("finger", "Trying to save capture template")
        self.timer.cancel()
        self.cap.save(os.path.abspath("%s/tmpl.jpg" % self.stgs["conf_path"]), self.cap.rect(100, 100, 150, 150))
Esempio n. 11
0
    def cap_template(self):
        """
        Captures the template

        Arguments:
        - self: The main object pointer.
        """

        debug.debug("finger", "Trying to save capture template")
        self.timer.cancel()
        self.cap.save(os.path.abspath("%s/tmpl.jpg" % self.stgs["conf_path"]), self.cap.rect(100, 100, 150, 150))
Esempio n. 12
0
    def load_template(self):
        """
        Loads the finger template if exists

        Arguments:
        - self: The main object pointer.
        """

        try:
            self.tmpl = co.hg.cvLoadImage("%s/tmpl.jpg" % self.stgs["conf_path"], 3)
            debug.debug("finger", "Loading template")
        except:
            pass
Esempio n. 13
0
    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
        """

        debug.debug("mousetrap.ocvfw.idm", "Setting Capture")
        self.cap = Capture(async=True, idx=cam, backend="OcvfwPython")
        self.cap.change(color="rgb")
        self.cap.set_camera("lk_swap", True)
Esempio n. 14
0
    def load_template(self):
        """
        Loads the finger template if exists

        Arguments:
        - self: The main object pointer.
        """

        try:
            self.tmpl = co.hg.cvLoadImage("%s/tmpl.jpg" % self.stgs["conf_path"], 3)
            debug.debug("finger", "Loading template")
        except:
            pass
Esempio n. 15
0
    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
        """

        debug.debug("mousetrap.ocvfw.idm", "Setting Capture")

        self.cap = Capture(async=False, idx=cam, backend="OcvfwPython")
        self.cap.change(color="rgb")
        self.cap.set_camera("lk_swap", True)