Beispiel #1
0
    def tune(self):
        tune_window = Window('Tune Window')
        colors = [(0, 255, 0), (255, 255, 0), (255, 0, 0), (0, 0, 255)]

        print
        print 'press Q to cancel the whole selection process'
        print

        try:
            print len(self.rect_points), self.rect_points
            print len(self.check_points[0]), self.check_points[0]
            print len(self.check_points[1]), self.check_points[1]
            print len(self.start_points), self.start_points
        except:
            pass

        while True:
            frame = self._get_video_frame()
            
            try:
                for p in self.rect_points:
                      cv2.circle(frame, p, 3, colors[0], thickness=2)
                
                for p in self.check_points[0]:
                    cv2.circle(frame, p, 3, colors[1], thickness=2)

                for p in self.check_points[1]:
                    cv2.circle(frame, p, 3, colors[2], thickness=2)

                for p in self.start_points:
                    cv2.circle(frame, p, 3, colors[3], thickness=2)
            except:
                pass

            tune_window.draw(frame)

            key_cmp = lambda k, c: k is ord(c.upper()) or k is ord(c.lower())
            key = tune_window.wait()
            if key_cmp(key, 'q'):
                tune_window.close()
                break; 
Beispiel #2
0
    def start(self, video):
        ps = PumpSpark()
        
        try:
            ps.pump2([
              ([(1, 254), (4, 254)], 10), 
              ([(2, 100), (5, 100)], 12),
              ([(1, 254), (4, 254)], 10)])  
        except:
           pass
        
        window = Window('Water Ira-Ira Bou')
        mask_window = Window('Mask')

        fps = video.get(cv.CV_CAP_PROP_FPS)
        if fps > 0:
            window.fps = fps

        h = int(video.get(cv.CV_CAP_PROP_FRAME_HEIGHT))
        w = int(video.get(cv.CV_CAP_PROP_FRAME_WIDTH))

        rect = bounding_rect(self.rect_points)
        cfilter_bar = ColorFilter(self.color_range_bar)
        cfilter_water = ColorFilter(self.color_range_water)
        searcher_bar = CheatSearcher(self.check_points[0])
        searcher_water = CheatSearcher(self.check_points[1])

        colors = [(0, 255, 0), (255, 255, 0)]
        ret, frame = video.read()
        if not ret:
            'frame is null'
        
        bar_index = 0
        water_index = 0
        start = False
        print self.color_range_bar
        while True:
            key = window.wait()

            if key is ord('Q') or key is ord('q'):
                break

            ret, frame = video.read()
            if not ret:
                break

            current_img = crop(frame, rect)

            mask_bar = cfilter_bar.get_mask(current_img)
            mask_water = cfilter_water.get_mask(current_img)

            bar_index, (x, y) = searcher_bar.search(mask_bar, bar_index)
            cv2.circle(current_img, (x, y), 3, colors[0], thickness=2)
            
            water_index, (x, y) = searcher_water.search(mask_water, water_index)
            cv2.circle(current_img, (x, y), 3, colors[0], thickness=2)

            mask_window.draw(mask_bar)
            window.draw(current_img)
            
            if bar_index != 0 and start == False:
                play_sound('sound/button-8.wav')
                start = True
            
        mask_window.close()
        window.close()
        ps.turnOff()