コード例 #1
0
class CameraTestCase(unittest.TestCase):
    def setUp(self):
        self.cam = Camera()

    def tearDown(self):
        del self.cam

    def test_img(self):
        img = self.cam.grab(0)
        self.assertEqual((self.cam.height, self.cam.width), np.shape(img))

    def test_radiance(self):
        img1 = self.cam.grab(0)
        img2 = self.cam.grab(self.cam.get_radiance_for(mean=250))
        self.assertLess(img1.mean(), img2.mean())
コード例 #2
0
ファイル: test_camera.py プロジェクト: EMVA1288/emva1288
class CameraTestCase(unittest.TestCase):
    def setUp(self):
        self.cam = Camera()

    def tearDown(self):
        del self.cam

    def test_img(self):
        img = self.cam.grab(0)
        self.assertEqual((self.cam.height, self.cam.width), np.shape(img))

    def test_radiance(self):
        img1 = self.cam.grab(0)
        img2 = self.cam.grab(self.cam.get_radiance_for(mean=250))
        self.assertLess(img1.mean(), img2.mean())
コード例 #3
0
    def test_bayer_layer(self):
        # Init the parameters
        h, w = [480, 640]
        wavelength = np.linspace(400, 800, 100)
        transmission_red = 670
        transmission_blue = 450
        transmission_green = 550
        b_layer = routines.get_bayer_filter(transmission_green,
                                            transmission_red,
                                            transmission_blue,
                                            transmission_green,
                                            w, h, wavelength)
        qe = routines.Qe(filter=b_layer)
        cam = Camera(width=w, height=h, qe=qe)
        # Initiata a cam without a bayer filter
        cam_d = Camera(width=w, height=h)
        # Set the camera for testing the layer
        target = cam.img_max / 2
        # Get the radiance to grab from the second cam. The output radiance
        # is affected by qe, so the bayer_filter as well
        radiance = cam_d.get_radiance_for(mean=target)
        img = cam.grab(radiance)
        green_filter = np.tile([[0, 1], [1, 0]], (int(h/2), int(w/2)))
        blue_filter = np.tile([[1, 0], [1, 1]], (int(h/2), int(w/2)))
        red_filter = np.tile([[1, 1], [0, 1]], (int(h/2), int(w/2)))

        gf = b_layer[0, 0, :].mean()
        rf = b_layer[0, 1, :].mean()
        bf = b_layer[1, 0, :].mean()
        # Test if the mean of the green it's 100% of the target +/- 5
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=green_filter).mean(),
            target * gf, delta=10,
            msg="green not in range")
        # Test if the mean of the red it's 15% of the target +/- 5
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=red_filter).mean(),
            target * rf, delta=10,
            msg="red not in range")
        # Test if the mean of the blue it's 2% of the target +/- 5
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=blue_filter).mean(),
            target * bf, delta=10,
            msg="blue not in range")
コード例 #4
0
 def test_prnu(self):
     # Init the parameters
     h, w = [480, 640]
     rep = 200
     value8 = 3
     # create the pattern of the prnu
     prnu_array = np.ones((8))
     prnu_array[-1] = value8
     prnu = routines.get_tile(prnu_array, h, w)
     # Set the camera for testing the prnu
     cam = Camera(width=w, height=h, prnu=prnu)
     var = np.sqrt(cam._sigma2_dark_0)
     target = cam.img_max / 2
     # The target (top_target) is the multiplication of the target
     # (what we expect without prnu) and the value8(prnu). We can do it
     # because if we look at the _u_e function in emva1288.camera.camera
     # the prnu affect the QE with a multiplication. So if we just
     # multiplied the target by the prnu it's the same thing.
     # But this value can go over the maximal value for one pixel, this
     # is why we use the min() function to take the maximal value than the
     # camera can take.
     top_target = min(target * value8, cam.img_max)
     radiance = cam.get_radiance_for(mean=target)
     img = cam.grab(radiance)
     # create the mask
     prnu_mask = np.zeros((8))
     prnu_mask[-1] = 1
     prnu_mask_resize = routines.get_tile(prnu_mask, h, w)
     prnu_non_mask = np.ones((8))
     prnu_non_mask[-1] = 0
     prnu_non_mask_resize = routines.get_tile(prnu_non_mask, h, w)
     # Test if the mean it's 100% of the target +/- variance
     self.assertAlmostEqual(np.ma.masked_array(
         img,
         mask=prnu_mask_resize).mean(),
         target, delta=var,
         msg="values are not in range")
     # Test if the mean of the 8th value it's value8
     # multiplied be the target +/- variance
     self.assertAlmostEqual(np.ma.masked_array(
         img,
         mask=prnu_non_mask_resize).mean(),
         top_target, delta=var,
         msg="8th value it's not in range")
コード例 #5
0
    def test_bayer_layer(self):
        # Init the parameters
        h = 480
        w = 640
        transmition_red = 0.15
        transmition_blue = 0.02
        transmition_green = 1.

        b_layer = routines.get_bayer_filter(transmition_green,
                                            transmition_red,
                                            transmition_blue,
                                            transmition_green, w, h)

        # Test if the b_layer have the same shape than what we give it
        self.assertEqual((h, w), b_layer.shape)

        # Set the camera for testing the layer
        cam = Camera(width=w, height=h, radiance_factor=b_layer)
        target = cam.img_max / 2
        radiance = cam.get_radiance_for(mean=target)
        img = cam.grab(radiance)
        green_filter = routines.get_bayer_filter(0, 1, 1, 0, w, h)
        blue_filter = routines.get_bayer_filter(1, 1, 0, 1, w, h)
        red_filter = routines.get_bayer_filter(1, 0, 1, 1, w, h)
        # Test if the mean of the green it's 100% of the target +/- 5%
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=green_filter).mean(),
            target, delta=5.0,
            msg="green not in range")
        # Test if the mean of the red it's 15% of the target +/- 5%
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=red_filter).mean(),
            target*transmition_red, delta=5.0,
            msg="red not in range")
        # Test if the mean of the green it's 2% of the target +/- 5%
        self.assertAlmostEqual(np.ma.masked_array(
            img,
            mask=blue_filter).mean(),
            target*transmition_blue, delta=5.0,
            msg="blue not in range")