Ejemplo n.º 1
0
 def compute_pointcloud(self, sketchup_model, theta, phi):
     self.load_model(sketchup_model)
     print "Computing view for model {} : t={}, p={}".format(
         sketchup_model.google_id, theta, phi)
     cloud = PointCloud()
     cloud._cpp_pointcloud = self._cpp_computer.compute_view(theta, phi)
     return cloud
Ejemplo n.º 2
0
 def compute_pointcloud(self, sketchup_model, theta, phi):
     self.load_model(sketchup_model)
     print "Computing view for model {} : t={}, p={}".format(
         sketchup_model.google_id, theta, phi)
     cloud = PointCloud()
     cloud._cpp_pointcloud = self._cpp_computer.compute_view(theta, phi)
     return cloud
Ejemplo n.º 3
0
def save_pointclouds(example_object, options):
    """ Extract pointclouds from tar archive. """
    sequences = list(example_object.sequences.all())
    frames = Frame.objects.filter(video_sequence__in=sequences)
    if not options['force']:
        frames = frames.filter(_pointcloud__isnull=True)
    if not frames.exists():
        return  # Nothing to process
    if options['download_folder'] is None:
        archive_dir = dowload_archives([example_object])
    else:
        archive_dir = options['download_folder']
    pcd_tar_path = "{}/pcd_tar/{}.tar".format(archive_dir, example_object.name)
    pcd_tar = tarfile.open(pcd_tar_path)
    tmp_dir = tempfile.mkdtemp()
    pcd_tar.extractall(tmp_dir)
    # pcd_members = dict((m.name, m) for m in pcd_tar.getmembers())
    for frame in frames.iterator():
        current_pcd = os.path.join(tmp_dir, frame.pcd_member_name())
        pointcloud = PointCloud.load_pcd(current_pcd)
        frame._pointcloud = pointcloud
        frame.save()
    shutil.rmtree(tmp_dir)
    if options['download_folder'] is None:
        shutil.rmtree(archive_dir)
Ejemplo n.º 4
0
def save_pointclouds(example_object, options):
    """ Extract pointclouds from tar archive. """
    sequences = list(example_object.sequences.all())
    frames = Frame.objects.filter(video_sequence__in=sequences)
    if not options['force']:
        frames = frames.filter(_pointcloud__isnull=True)
    if not frames.exists():
        return  # Nothing to process
    if options['download_folder'] is None:
        archive_dir = dowload_archives([example_object])
    else:
        archive_dir = options['download_folder']
    pcd_tar_path = "{}/pcd_tar/{}.tar".format(archive_dir,
                                              example_object.name)
    pcd_tar = tarfile.open(pcd_tar_path)
    tmp_dir = tempfile.mkdtemp()
    pcd_tar.extractall(tmp_dir)
    # pcd_members = dict((m.name, m) for m in pcd_tar.getmembers())
    for frame in frames.iterator():
        current_pcd = os.path.join(tmp_dir, frame.pcd_member_name())
        pointcloud = PointCloud.load_pcd(current_pcd)
        frame._pointcloud = pointcloud
        frame.save()
    shutil.rmtree(tmp_dir)
    if options['download_folder'] is None:
        shutil.rmtree(archive_dir)
Ejemplo n.º 5
0
 def test_identification_banana_vs_bowl_vs_food_can(self):
     """ Try to identify with 3 categories. """
     # Getting the dataset
     bowl_ids = ['fa61e604661d4aa66658ecd96794a1cd',
                 'f74bba9a22e044dea3769fcd5f96f4',
                 'd2e1dc9ee02834c71621c7edb823fc53']
     banana_ids = ['f6e6117261dca163713c042b393cc65b',
                   'ba0d56295321002718ddbf38fa69c501',
                   '7d78e217e0ba160fe2b248b8bb97d290']
     bowls = []
     for bowl_id in bowl_ids:
         bowls.append(SketchupModel.find_google_id(bowl_id))
     bananas = []
     for banana_id in banana_ids:
         bananas.append(SketchupModel.find_google_id(banana_id))
     # Training
     iden = Identifier()
     iden.add_models(bananas, 'banana')
     iden.add_models(bowls, 'bowl')
     iden.train()
     # Identification
     for i in range(20):
         example = Example.get_random(['banana', 'bowl'])
         pcd_file = example.pcd_file()
         print "Identification of file {}".format(example)
         cloud = PointCloud.load_pcd(pcd_file.name)
         iden.identify(cloud)
Ejemplo n.º 6
0
 def test_save_load_pcd(self):
     """ Test that PointClouds can be save and load functions. """
     pcd_file = open("pointcloud/fixtures/cloud.pcd")
     pointcloud = PointCloud.load_pcd(pcd_file.name)
     self.assertEqual(pointcloud.size(), 8)
     with tempfile.NamedTemporaryFile() as temp_file:
         pointcloud.save_pcd(temp_file.name)
         temp_file.seek(0)
         self.assertTrue(temp_file.read() == pcd_file.read())
Ejemplo n.º 7
0
 def test_save_load_pcd(self):
     """ Test that PointClouds can be save and load functions. """
     pcd_file = open("pointcloud/fixtures/cloud.pcd")
     pointcloud = PointCloud.load_pcd(pcd_file.name)
     self.assertEqual(pointcloud.size(), 8)
     with tempfile.NamedTemporaryFile() as temp_file:
         pointcloud.save_pcd(temp_file.name)
         temp_file.seek(0)
         self.assertTrue(temp_file.read() == pcd_file.read())
Ejemplo n.º 8
0
 def compute_pointcloud(self):
     """ Extract the pointcloud from the ExampleObject archive. """
     import tarfile
     from tempfile import NamedTemporaryFile
     from django_server.settings import MEDIA_ROOT
     example_object = self.video_sequence.example_object
     temp_file = NamedTemporaryFile(delete=True)
     pcd_tar = tarfile.open(MEDIA_ROOT + example_object.pcd_tar.name)
     temp_file.write(pcd_tar.extractfile(self.pcd_member_name()).read())
     temp_file.flush()
     pointcloud = PointCloud.load_pcd(temp_file.name)
     return pointcloud
Ejemplo n.º 9
0
 def compute_pointcloud(self):
     """ Extract the pointcloud from the ExampleObject archive. """
     import tarfile
     from tempfile import NamedTemporaryFile
     from django_server.settings import MEDIA_ROOT
     example_object = self.video_sequence.example_object
     temp_file = NamedTemporaryFile(delete=True)
     pcd_tar = tarfile.open(MEDIA_ROOT + example_object.pcd_tar.name)
     temp_file.write(pcd_tar.extractfile(self.pcd_member_name()).read())
     temp_file.flush()
     pointcloud = PointCloud.load_pcd(temp_file.name)
     return pointcloud
Ejemplo n.º 10
0
 def test_exception_when_no_existing_category(self):
     """ Test that if the identifier is empty it throws. """
     pointcloud = PointCloud.load_pcd("pointcloud/fixtures/cloud.pcd")
     identifier = Identifier()
     self.assertRaises(IndexError, identifier.identify, pointcloud)
     # training will add a category :
     model = SketchupModel()
     model.google_id = "test1"
     model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
     identifier.add_models([model], "test_category")
     try:
         identifier.identify(pointcloud)
     except IndexError:
         self.fail("identifier.identify() raised IndexError unexpectedly!")
     except:
         # can raise if Indentification failed
         pass
Ejemplo n.º 11
0
 def test_basis(self):
     """ Test init of a PointCloud. """
     cloud = PointCloud()
     self.assertEqual(cloud.size(), 0)
Ejemplo n.º 12
0
 def test_basis(self):
     """ Test init of a PointCloud. """
     cloud = PointCloud()
     self.assertEqual(cloud.size(), 0)