Ejemplo n.º 1
0
    def getCrossings(self, cc, horizontal):
        if horizontal:
            step = cc.normalized.shape[1] / float(self.count_crossings + 1)
        else:
            step = cc.normalized.shape[0] / float(self.count_crossings + 1)

        counts = []
        mins = []
        maxs = []
        for i in range(self.count_crossings):
            pos = int((i + 1) * step)

            # the crossing is threated in terms of boolean intervals...
            booleans = []
            if horizontal:
                #horizontal -> y fixed and x moves
                for x in range(cc.normalized.shape[1]):
                    booleans.append(cc.normalized[pos, x] > 128.0)

            else:
                #vertical -> x fixed and y moves
                for y in range(cc.normalized.shape[0]):
                    booleans.append(cc.normalized[y, pos] > 128.0)

            # find the intervals...
            intervals = MiscHelper.findBooleanIntervals(booleans, True)

            # now, get the middle points for each interval...
            midPoints = MiscHelper.intervalMidPoints(intervals)

            # normalize values
            midPoints = MiscHelper.scaleValues(midPoints, 0,
                                               cc.normalized.shape[0] - 1, -1,
                                               1)

            counts.append(len(intervals))

            if len(intervals) > 0:
                mins.append(midPoints[0])
                maxs.append(midPoints[-1])
            else:
                mins.append(1.1)
                maxs.append(-1.1)

        counts = MiscHelper.scaleValues(counts, 0, 10, -3, 3)

        return counts + mins + maxs
    def selectMotionlessFrames(self):
        #maximum motion allowed
        threshold = 0

        booleans = []
        for idx, m in enumerate(self.motion_detected):
            booleans.append(m.count_changes <= threshold)

        intervals = MiscHelper.findBooleanIntervals(booleans, True)

        #only consider intervals of at least 3 frames
        candidates = []
        for ini, end in intervals:
            #check....
            if end - ini >= 2:
                #pick the frame in the middle of the interval
                middle = self.motion_detected[int((end + ini) / 2.0)]
                candidates.append((middle.video_index, middle.time))

        return candidates
    def getNonblockedIntervals(self, region_box, max_width, max_height,
                               init_index, end_time):
        #Find a frame where the found region has no motion around

        pos = init_index
        blocked_list = []

        while pos < len(self.motion_detected) and \
              self.motion_detected[pos].absolute_time < end_time:

            #check motion[pos] to see if main_region is blocked
            blocked = self.motion_detected[pos].isBlockingRegion(
                region_box, max_width, max_height, 3.0, 3.0)

            #add to boolean list
            blocked_list.append(blocked)

            pos += 1

        #now find the intervals where it is not obstruded...
        intervals = MiscHelper.findBooleanIntervals(blocked_list, False)

        return intervals