Exemplo n.º 1
0
    def predict_corners(self, new_corners):
        '''
        If in new_corners are Nones then this function tries to predict where
        not found corners are
        @param new_corners:
        '''
        db.db_break()
        new_corners = self._improve_corners(new_corners)
        self.validate_corners(new_corners)
        corners = filter(lambda x: x is not None, new_corners)
        def cmp(x, y):
            if  x.similarity > y.similarity:
                return  1
            else: return - 1
        corners = sorted(corners, cmp)
        self.avg_sim = reduce(lambda x, y: x + y.similarity, corners, 0)
        while len(corners) > 0:
            ncorners = list(new_corners)
            self.avg_sim /= len(corners)
            self._predict_corners(ncorners)
            if all(ncorners):
                if cv.CheckContourConvexity([x.p for x in ncorners]) == 1:
                    le = len(ncorners)
                    for i,c in enumerate(ncorners):
                        n= (i+1)%le
                        ncorners[n].prev = c.p
                        c.next = ncorners[n].p
                    for c in ncorners:c.measure()
                    return ncorners
            last = corners[-1]
            new_corners[last.id] = None
            self.avg_sim = self.avg_sim * len(corners) - last.similarity
            corners.remove(last)

        return None
Exemplo n.º 2
0
    def find_corners(self):
        '''
        Tries to find corners or to predict them. Return empty list,
        if every corner is found, or list of points in the area which tell where
        to do futher checking
        '''
        time = self.m_d.time
        if time-self.last_seen >= MAX_SEEN:
            return False
        #cv.ResetImageROI(draw_img)
        ncorners = []
        bounds = []
        for c in self.corners:
            db.db_break("find_corners")
            cands = c.get_candidates(self.m_d)
            min = NOT_SIMILLAR;
            bestcand = None;
            for cand in cands:
                if cand.similarity < min:
                    min = cand.similarity;
                    bestcand = cand
            ncorners.append(bestcand)
            bounds.extend(cvrect(cv.GetImageROI(self.m_d.bw_img)))
            if bestcand is None:
                pass

        db.pr([ncorners], "find_corners")
        for cor in ncorners:
            if cor is not None:
                cor.draw(self.m_d.tmp_img)
        if None in ncorners:
            pass
        CP = CornerPredictor(self.corners, time, self.m_d)
        ncorners = CP.predict_corners(ncorners)
        db.pr([ncorners], "new corners")
        if ncorners is not None:
            points = [x.p for x in ncorners]
            correctness = self.code_correctness(points)
            if correctness>REQUIRED_CORRECTNESS:
                self.set_new_position(ncorners)
                return True
            else:
                db.PolyLine(self.m_d.tmp_img,[points], True, (255,255,255),
                            "%.2f"%correctness)
        self.m_d.borders.extend(CP.bounds)
        return False
Exemplo n.º 3
0
    def find_corners(self):
        '''
        Tries to find corners or to predict them. Return empty list,
        if every corner is found, or list of points in the area which tell where
        to do futher checking
        '''
        time = self.m_d.time
        if time - self.last_seen >= MAX_SEEN:
            return False
        #cv.ResetImageROI(draw_img)
        ncorners = []
        bounds = []
        for c in self.corners:
            db.db_break("find_corners")
            cands = c.get_candidates(self.m_d)
            min = NOT_SIMILLAR
            bestcand = None
            for cand in cands:
                if cand.similarity < min:
                    min = cand.similarity
                    bestcand = cand
            ncorners.append(bestcand)
            bounds.extend(cvrect(cv.GetImageROI(self.m_d.bw_img)))
            if bestcand is None:
                pass

        db.pr([ncorners], "find_corners")
        for cor in ncorners:
            if cor is not None:
                cor.draw(self.m_d.tmp_img)
        if None in ncorners:
            pass
        CP = CornerPredictor(self.corners, time, self.m_d)
        ncorners = CP.predict_corners(ncorners)
        db.pr([ncorners], "new corners")
        if ncorners is not None:
            points = [x.p for x in ncorners]
            correctness = self.code_correctness(points)
            if correctness > REQUIRED_CORRECTNESS:
                self.set_new_position(ncorners)
                return True
            else:
                db.PolyLine(self.m_d.tmp_img, [points], True, (255, 255, 255),
                            "%.2f" % correctness)
        self.m_d.borders.extend(CP.bounds)
        return False