コード例 #1
0
 def test_init_without_overwrite(self):
     # For image.
     image_media = op.join(self.work_dir, 'images')
     os.makedirs(image_media)
     with self.assertRaises(ValueError):
         backendMedia.MediaWriter(media_type='pictures',
                                  image_media=image_media)
     # For mask.
     mask_media = op.join(self.work_dir, 'masks')
     os.makedirs(mask_media)
     with self.assertRaises(ValueError):
         backendMedia.MediaWriter(media_type='pictures',
                                  mask_media=mask_media)
コード例 #2
0
 def test_close_without_error(self):
     # Pictures.
     writer = backendMedia.MediaWriter(media_type='pictures',
                                       image_media=op.join(
                                           self.work_dir, 'pictures'))
     writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8))
     writer.close()
     # Video.
     writer = backendMedia.MediaWriter(media_type='video',
                                       image_media=op.join(
                                           self.work_dir, 'video.avi'))
     writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8))
     writer.close()
コード例 #3
0
 def test_init_without_overwrite(self):
     # For image.
     image_media = op.join(self.work_dir, 'images.avi')
     with open(image_media, 'w'):
         pass
     with self.assertRaises(ValueError):
         backendMedia.MediaWriter(media_type='video',
                                  image_media=image_media)
     # For mask.
     mask_media = op.join(self.work_dir, 'masks.avi')
     with open(mask_media, 'w'):
         pass
     with self.assertRaises(ValueError):
         backendMedia.MediaWriter(media_type='video', mask_media=mask_media)
コード例 #4
0
 def test_pictures_maskwrite(self):
     mask_media = op.join(self.work_dir, 'masks')
     writer = backendMedia.MediaWriter(media_type='pictures',
                                       mask_media=mask_media)
     writer.maskwrite(np.zeros((100, 100), dtype=np.uint8))
     writer.close()
     self.assertTrue(op.exists(op.join(mask_media, '000000.png')))
コード例 #5
0
 def test_pictures_imwrite(self):
     image_media = op.join(self.work_dir, 'images')
     writer = backendMedia.MediaWriter(media_type='pictures',
                                       image_media=image_media)
     writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8))
     writer.close()
     self.assertTrue(op.exists(op.join(image_media, '000000.jpg')))
コード例 #6
0
 def test_init_create_dir(self):
     image_media = op.join(self.work_dir, 'images')
     mask_media = op.join(self.work_dir, 'masks')
     backendMedia.MediaWriter(media_type='pictures',
                              image_media=image_media,
                              mask_media=mask_media)
     self.assertTrue(op.exists(image_media))
     self.assertTrue(op.exists(mask_media))
コード例 #7
0
 def test_init_no_extension(self):
     # Instead of "images.avi".
     image_media = op.join(self.work_dir, 'images')
     writer = backendMedia.MediaWriter(media_type='video',
                                       image_media=image_media)
     with self.assertRaises(TypeError):
         writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8))
     writer.close()
コード例 #8
0
 def test_maskwrite_namehint(self):
     mask_media = op.join(self.work_dir, 'masks')
     writer = backendMedia.MediaWriter(media_type='pictures',
                                       mask_media=mask_media)
     mask_gt = skimage.io.imread('testdata/cars/masks/000000.png')
     writer.close()
     writer.maskwrite(mask_gt, namehint='mymask')
     mask = skimage.io.imread(op.join(mask_media, 'mymask.png'))
     self.assertLess(_diff(mask, mask_gt), 0.002)
     writer.close()
コード例 #9
0
 def test_video_init_create_files(self):
     image_media = op.join(self.work_dir, 'images.avi')
     mask_media = op.join(self.work_dir, 'masks.avi')
     writer = backendMedia.MediaWriter(media_type='video',
                                       image_media=image_media,
                                       mask_media=mask_media)
     writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8))
     writer.maskwrite(np.zeros((100, 100), dtype=np.uint8))
     writer.close()
     self.assertTrue(op.exists(image_media))
     self.assertTrue(op.exists(mask_media))
コード例 #10
0
 def test_init_overwrite_files(self):
     image_media = op.join(self.work_dir, 'images.avi')
     mask_media = op.join(self.work_dir, 'masks.avi')
     with open(image_media, 'w'):
         pass
     with open(mask_media, 'w'):
         pass
     writer = backendMedia.MediaWriter(media_type='video',
                                       image_media=image_media,
                                       mask_media=mask_media,
                                       overwrite=True)
     writer.close()
     self.assertTrue(op.exists(image_media))
     self.assertTrue(op.exists(mask_media))
コード例 #11
0
 def test_init_overwrite_dirs(self):
     image_media = op.join(self.work_dir, 'images')
     mask_media = op.join(self.work_dir, 'masks')
     os.makedirs(image_media)
     os.makedirs(mask_media)
     with open(op.join(image_media, 'myfile'), 'w'):
         pass
     with open(op.join(mask_media, 'myfile'), 'w'):
         pass
     backendMedia.MediaWriter(media_type='pictures',
                              image_media=image_media,
                              mask_media=mask_media,
                              overwrite=True)
     # Check that dirs are recreated.
     self.assertTrue(op.exists(image_media))
     self.assertTrue(op.exists(mask_media))
     # Check that files dissapeared from the dirs.
     self.assertFalse(op.exists(op.join(image_media, 'myfile')))
     self.assertFalse(op.exists(op.join(mask_media, 'myfile')))
コード例 #12
0
 def test_close_uninit_without_error(self):
     writer = backendMedia.MediaWriter(media_type='pictures')
     writer.close()
     writer = backendMedia.MediaWriter(media_type='video')
     writer.close()