Пример #1
0
    def handle(self, *args, **options):
        admin_user = User.objects.get_or_create(
            username='******')[0].get_profile()

        delete = bool(options['delete'])

        print 'Visiting: %s' % args[0]
        for root, dirs, files in os.walk(args[0]):
            print 'Visiting %s: %d files' % (root, len(files))

            # only create a category if has at least one photo
            scene_category = None

            num_added = 0
            for filename in progress.bar(files):
                if filename.endswith(".jpg"):
                    path = os.path.join(root, filename)

                    split = filename.rindex('_')
                    flickr_username = filename[:split]
                    flickr_id = filename[split + 1:filename.rindex('.')]
                    flickr_user = FlickrUser.objects.get_or_create(
                        username=flickr_username)[0]

                    #license = License.objects.get_or_create(
                        #user=user, name='CC BY-NC-SA 2.0')[0]

                    if not scene_category:
                        name = os.path.basename(root).replace('+', ' ')
                        scene_category, _ = PhotoSceneCategory.objects \
                            .get_or_create(name=name)

                    try:
                        add_photo(
                            path=path,
                            user=admin_user,
                            scene_category=scene_category,
                            flickr_user=flickr_user,
                            flickr_id=flickr_id,
                            license=None,
                            must_have_exif=True,
                            must_have_fov=True,
                        )
                    except Exception as e:
                        print '\nNot adding photo:', e
                    else:
                        print '\nAdded photo:', path
                        num_added += 1

                    if delete:
                        from common.tasks import os_remove_file
                        os_remove_file.delay(path)

            print 'Added %d photos to %s' % (num_added, root)
Пример #2
0
    def handle(self, *args, **options):
        admin_user = User.objects.get_or_create(
            username='******')[0].get_profile()

        with transaction.atomic():
            for root in progress_bar(glob.glob('%s/*' % args[0])):
                slug = os.path.basename(root)
                print slug

                if 'janivar50' in slug or 'kitchen' in slug:
                    scene_category = PhotoSceneCategory.objects.get(
                        name='kitchen')
                elif 'mike_indoor' in slug or 'sofas' in slug:
                    scene_category = PhotoSceneCategory.objects.get(
                        name='living room')
                else:
                    raise ValueError("Unknown")

                light_stack = PhotoLightStack.objects.create(slug=slug)

                files = glob.glob('%s/*' % root)
                photos = [
                    add_photo(
                        path=f,
                        user=admin_user,
                        scene_category=scene_category,
                        light_stack=light_stack,
                    )
                    for f in files
                ]
Пример #3
0
    def handle(self, *args, **options):
        admin_user = User.objects.get_or_create(
            username='******')[0].get_profile()
        print 'user:'******'kitchen'
        scene_category, _ = PhotoSceneCategory.objects \
            .get_or_create(name=name)

        path = args[0]
        if not path:
            print 'No path'
            return

        try:
            photo = add_photo(
                path=path,
                user=admin_user,
                scene_category=scene_category,
                flickr_user=None,
                flickr_id=None,
                license=None,
                exif='',
                fov=None,
            )
        except Exception as e:
            print '\nNot adding photo:', e
        else:
            print '\nAdded photo:', path
            photo.synthetic = True
            photo.save()
Пример #4
0
    def handle(self, *args, **options):
        if len(args) != 3:
            print 'Please supply a folder and the name of the dataset.'
            return

        username = args[0]
        dataset_name = args[1]
        folder = args[2]

        delete = bool(options['delete'])

        user = UserProfile.objects.get(user__username=username)

        print 'Visiting: %s' % folder
        for root, dirs, files in os.walk(folder):
            print 'Visiting %s: %d files' % (root, len(files))

            # only create a category if has at least one photo
            dataset, _ = PhotoDataset.objects.get_or_create(name=dataset_name)

            num_added = 0
            for filename in progress.bar(files):
                if filename.endswith(".jpg"):
                    path = os.path.join(root, filename)

                    flickr_username = None
                    flickr_id = None
                    flickr_user = None
                    name, _ = os.path.splitext(os.path.basename(filename))

                    #license = License.objects.get_or_create(
                    #user=admin_user, name='CC BY-NC-SA 2.0')[0]

                    try:
                        add_photo(
                            path=path,
                            user=user,
                            dataset=dataset,
                            flickr_user=flickr_user,
                            flickr_id=flickr_id,
                            #license=license,
                            must_have_exif=False,
                            must_have_fov=False,
                            exif='',
                            synthetic=False,
                            inappropriate=False,
                            rotated=False,
                            stylized=False,
                            nonperspective=False,
                            name=name,
                        )
                    except Exception as e:
                        print '\nNot adding photo:', e
                    else:
                        print '\nAdded photo:', path
                        num_added += 1

                    if delete:
                        from common.tasks import os_remove_file
                        os_remove_file.delay(path)

            print 'Added %d photos to %s' % (num_added, root)
    def handle(self, *args, **options):
        admin_user = User.objects.get_or_create(
            username='******')[0].get_profile()

        for filename in progress_bar(args):
            if not os.path.exists(filename):
                raise ValueError("File does not exist: '%s'" % filename)

            blendswap_id = os.path.basename(filename).split('_')[0]
            license, scene_url, scene_artist = \
                License.get_for_blendswap_scene(blendswap_id)

            print 'file:', filename
            print 'license:', license
            print 'url:', scene_url
            print 'artist:', scene_artist

            tmpdir = tempfile.mkdtemp()
            try:
                print "Loading %s..." % filename
                md5 = md5sum(filename)
                if IntrinsicSyntheticDecomposition.objects.filter(md5=md5).exists():
                    print "Already added: %s" % filename
                    continue

                multilayer = open_multilayer_exr(
                    filename, tonemap=True, thumb_size=512, show_progress=True)
                paths = {}
                for key, img in multilayer.iteritems():
                    path = os.path.join(tmpdir, '%s-%s.jpg' % (md5, key))
                    img.save(path)
                    paths[key] = path

                with transaction.atomic():
                    photo = add_photo(
                        path=paths["combined"],
                        user=admin_user,
                        license=license,
                        synthetic=True,
                        whitebalanced=True,
                        inappropriate=False,
                        nonperspective=False,
                        stylized=False,
                        rotated=False,
                    )

                    print "Uploading layers: %s..." % paths.keys()
                    IntrinsicSyntheticDecomposition.objects.create(
                        photo=photo,
                        multilayer_exr=ImageFile(open(filename, 'rb')),
                        scene_artist=scene_artist,
                        scene_url=scene_url,
                        md5=md5,
                        **{
                            ("%s_thumb" % key): ImageFile(open(path, 'rb'))
                            for key, path in paths.iteritems()
                            if key != "combined"
                        }
                    )
            finally:
                shutil.rmtree(tmpdir)

        update_synthetic_diff_intensity()
    def handle(self, *args, **options):
        admin_user = User.objects.get_or_create(
            username='******')[0].get_profile()

        for filename in progress_bar(args):
            if not os.path.exists(filename):
                raise ValueError("File does not exist: '%s'" % filename)

            blendswap_id = os.path.basename(filename).split('_')[0]
            license, scene_url, scene_artist = \
                License.get_for_blendswap_scene(blendswap_id)

            print 'file:', filename
            print 'license:', license
            print 'url:', scene_url
            print 'artist:', scene_artist

            tmpdir = tempfile.mkdtemp()
            try:
                print "Loading %s..." % filename
                md5 = md5sum(filename)
                if IntrinsicSyntheticDecomposition.objects.filter(
                        md5=md5).exists():
                    print "Already added: %s" % filename
                    continue

                multilayer = open_multilayer_exr(filename,
                                                 tonemap=True,
                                                 thumb_size=512,
                                                 show_progress=True)
                paths = {}
                for key, img in multilayer.iteritems():
                    path = os.path.join(tmpdir, '%s-%s.jpg' % (md5, key))
                    img.save(path)
                    paths[key] = path

                with transaction.atomic():
                    photo = add_photo(
                        path=paths["combined"],
                        user=admin_user,
                        license=license,
                        synthetic=True,
                        whitebalanced=True,
                        inappropriate=False,
                        nonperspective=False,
                        stylized=False,
                        rotated=False,
                    )

                    print "Uploading layers: %s..." % paths.keys()
                    IntrinsicSyntheticDecomposition.objects.create(
                        photo=photo,
                        multilayer_exr=ImageFile(open(filename, 'rb')),
                        scene_artist=scene_artist,
                        scene_url=scene_url,
                        md5=md5,
                        **{("%s_thumb" % key): ImageFile(open(path, 'rb'))
                           for key, path in paths.iteritems()
                           if key != "combined"})
            finally:
                shutil.rmtree(tmpdir)

        update_synthetic_diff_intensity()