Beispiel #1
0
 def test_filter(self):
     im3 = cv2.imread('tests/reddot_seed.jpg', cv2.CV_LOAD_IMAGE_COLOR)
     f = CalibrateRedDotFilter()
     meta_img = MetaImg(im3, {})
     f(meta_img)
     self.assertTrue(meta_img.meta['ok'])
     self.assertLess(abs(meta_img.meta['mm_on_px'] - 0.0105), 0.005)
Beispiel #2
0
    def _test_remove_reddot(self, img):

        f0 = CalibrateRedDotFilter()
        f1 = SeparateObjectFilter()
        meta_img = MetaImg(img, {})
        f0.filter(meta_img)
        f1.filter(meta_img)
        self.assertLess(np.sum(meta_img.meta['mask']) / 255, 40)
Beispiel #3
0
 def test_no_red_dot(self):
     im3 = cv2.imread('tests/lena.jpg', cv.CV_LOAD_IMAGE_COLOR)
     f1 = SeparateObjectFilter()
     meta_img = MetaImg(im3, {})
     try:
         f1.filter(meta_img)
     except:
         self.fail()
Beispiel #4
0
 def test_chess_speed(self):
     im3 = cv2.imread('tests/reddot_seed.jpg', cv2.CV_LOAD_IMAGE_COLOR)
     f1 = CalibrateRedDotFilter({'dims': (4, 4), 'dot_diameter_in_mm': 5})
     t = time()
     for i in xrange(25):
         meta_img = MetaImg(np.array(im3), {})
         f1.filter(meta_img)
     t2 = time()
     self.assertLess(t2 - t, 4)
Beispiel #5
0
    def test_empty_filter(self):
        class EmptyFilter(BaseFilter):
            def filter(self, meta_img):
                return meta_img

        f1 = EmptyFilter()
        meta_img = MetaImg('asd', {})
        f1(meta_img)
        self.assertEqual(meta_img.img, 'asd')
Beispiel #6
0
    def test_measure(self):
        im3 = cv2.imread('tests/reddot_seed.jpg', cv.CV_LOAD_IMAGE_COLOR)
        f1 = CalibrateRedDotFilter({'dims': (4, 4), 'dot_diameter_in_mm': 5})
        f2 = SeparateObjectFilter()

        meta_img = MetaImg(im3, {})
        f1(meta_img)
        f2(meta_img)
        print meta_img.meta['ellipsis']
Beispiel #7
0
 def test_speed(self):
     im3 = cv2.imread('tests/reddot_seed.jpg', cv.CV_LOAD_IMAGE_COLOR)
     f1 = SeparateObjectFilter()
     t = time()
     for i in xrange(5):
         meta_img = MetaImg(im3, {})
         f1.filter(meta_img)
     t2 = time()
     self.assertLess(t2 - t, 5)
Beispiel #8
0
    def full_fitlers_test(self):
        im3 = cv2.imread('tests/reddot_seed.jpg', cv.CV_LOAD_IMAGE_COLOR)
        f1 = CalibrateRedDotFilter({'dims': (4, 4), 'dot_diameter_in_mm': 5})
        f2 = SeparateObjectFilter()

        t = time()
        for i in xrange(5):
            meta_img = MetaImg(np.array(im3), {})
            f1.filter(meta_img)
            f2.filter(meta_img)
        t2 = time()
        self.assertLess(t2 - t, 5)  #at least 2 frames for second
Beispiel #9
0
    def test_bg_probability(self):
        im3 = cv2.imread('tests/reddot_seed.jpg', cv.CV_LOAD_IMAGE_COLOR)
        f1 = SeparateObjectFilter()
        meta_img = MetaImg(im3, {})
        hsv = cv2.cvtColor(meta_img.img, cv.CV_BGR2HSV)
        mask = f1._create_bg_probe_mask(im3)

        probab = f1._bg_probability(mask, hsv[:, :, 2])
        _, ret = cv2.threshold((probab * 10000).astype(np.uint8), 70, 255,
                               cv2.THRESH_BINARY_INV)
        cv2.imshow('asd1', ret)
        probab += f1._bg_probability(mask, hsv[:, :, 0])

        probab *= 10000
        probab = probab.astype(np.uint8)
        print np.max(probab)
        _, ret = cv2.threshold(probab, 140, 255, cv2.THRESH_BINARY_INV)
Beispiel #10
0
    def run(self):
        while True:
            ret, self.frame = self.cam.read()
            vis = self.frame.copy()
            meta_img = MetaImg(vis, {})
            self.calib_filter(meta_img)
            self.sep_filter(meta_img)
            cv2.imshow('win', meta_img.img)
            ch = 0xFF & cv2.waitKey(5)
            if meta_img.meta.get('ellipsis', False):
                print(
                    'w', meta_img.meta['ellipsis'][1][0] *
                    meta_img.meta['mm_on_px'], 'h',
                    meta_img.meta['ellipsis'][1][1] *
                    meta_img.meta['mm_on_px'])
            if ch == 27:
                break

        cv2.destroyAllWindows()
Beispiel #11
0
 def on_frame(self):
     ret, frame = self.read_cam()
     if ret:
         self.vis = frame.copy()
         if self._show_detail:
             vis_small = self._downscale_2(self.vis)
         else:
             vis_small = self._downscale_4(self.vis)
         
         if self._frame_count % 15 == 0:
             self.meta_img = MetaImg(vis_small, {})
             self.calib_filter(self.meta_img)
             self.sep_filter(self.meta_img)
             self._frame_count = 0
         meta = self.meta_img.meta
         self._add_overlays(meta, vis_small)
         self.video_widget.push_frame(vis_small)
         self._frame_count += 1
     else:
         self._reset_cam(self._prev_grab_res)
Beispiel #12
0
 def test_elipse(self):
     im3 = cv2.imread('tests/reddot_seed.jpg', cv.CV_LOAD_IMAGE_COLOR)
     f1 = SeparateObjectFilter()
     meta_img = MetaImg(im3, {})
     f1.filter(meta_img)
     self.assertTrue(meta_img.meta.get('ellipsis', False))
Beispiel #13
0
 def test_gray(self):
     f1 = CalibrateRedDotFilter()
     meta_img = MetaImg(self.lena3, {})
     f1(meta_img)
     self.assertEqual(meta_img.gray.shape[:2], self.lena3_ref.shape[:2])
Beispiel #14
0
 def test_no_object(self):
     im3 = cv2.imread('tests/no_object.jpg', cv.CV_LOAD_IMAGE_COLOR)
     f1 = SeparateObjectFilter()
     meta_img = MetaImg(im3, {})
     #        try:
     f1.filter(meta_img)