python类mimwrite()的实例源码

image.py 文件源码 项目:pcbot 作者: pckv 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def modify(self, function, *args, **kwargs):
        """ Modify the image object using the given Image function.
        This function supplies sequence support. """
        if not gif_support or not self.gif:
            self.object = function(self.object, *args, **kwargs)
        else:
            frames = []
            duration = self.object.info.get("duration") / 1000
            for frame in ImageSequence.Iterator(self.object):
                frame_bytes = utils.convert_image_object(function(frame, *args, **kwargs))
                frames.append(imageio.imread(frame_bytes, format="PNG"))

            # Save the image as bytes and recreate the image object
            image_bytes = imageio.mimwrite(imageio.RETURN_BYTES, frames, format=self.format, duration=duration)
            self.object = Image.open(BytesIO(image_bytes))
            self.gif_bytes = image_bytes
camera.py 文件源码 项目:ctrl-f-vision 作者: osmanio2 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def gifwrite(name, img_buf):
    print("Thread spawned"*7)
    kargs = { 'quantizer':'nq' }
    imageio.mimwrite(name + ".gif", img_buf, 'GIF-FI', **kargs)
    # write additional data inside json
    fp = open("../records/%s.json" % name, 'w')
    fp.write("{\n")
    fp.write("    \"id\": 123,");
    fp.write("    \"gifUrl\": \"%s.gif\", \n" % name);
    fp.write("    \"timestamp\": \"%s\", \n" %
                             str(datetime.datetime.now()))
    fp.write("    \"tags\": [\"andrej\",\"hack\"]");
    fp.write("}\n")
    fp.close()

# main loop
visualize.py 文件源码 项目:DeepVideo 作者: AniketBajpai 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def visualize(name):
    for counter, file in enumerate(sorted(glob.glob(os.path.join(args.train_dir, '{}_*.hy'.format(name))), key=os.path.getmtime)[-args.n:]):
        print (file)
        f = h5py.File(file, 'r')
        # I = np.zeros((args.h, args.num_frames * args.w, args.c))
        generated_frames = f[f.keys()[0]]
        _, _, h, w, c = generated_frames.shape
        h_low = (h - args.h) / 2
        h_high = (h + args.h) / 2
        w_low = (w - args.w) / 2
        w_high = (w + args.w) / 2
        # Take only first set of frames from batch
        II = []
        if args.c == 1:
            for j in range(args.num_frames):
                I = np.reshape(generated_frames[0, j, h_low:h_high, w_low:w_high, 0], (args.h, args.w))
                if (I < 1.0).all() and (I > -1.0).all():
                    print ('Image in [-1, 1]')
                    I = ((I + 1.0) / 2 * 255).astype(np.int32)

                II.append(I)

        else:
            for j in range(args.num_frames):
                I = np.reshape(generated_frames[0, j, h_low:h_high, w_low:w_high, 0:args.c], (args.h, args.w, args.c))
                II.append(I)

        # II = np.stack(II)
        output_img_path = './outputs/{}_{}_{}.png'.format(args.output_prefix, name, str(counter))
        print ('Writing image:', output_img_path)
        print (len(II), II[0].shape)
        imageio.mimwrite(output_img_path, II)
animation.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def save(self, path):

        """
        This function ...
        :param path:
        :param fps:
        :return:
        """

        # Create and write the GIF file
        imageio.mimwrite(path, self.frames, fps=self.fps)

    # -----------------------------------------------------------------
animation.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def save(self, path):

        """
        This function ...
        :param path:
        :param fps:
        :return:
        """

        # Create and write the GIF file
        imageio.mimwrite(path, self.frames, fps=self.fps)

    # -----------------------------------------------------------------
pcollector.py 文件源码 项目:TensorArtist 作者: vacancy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _save_gif(traj, filename):
    traj = np.asarray(traj, dtype='uint8')
    return imageio.mimwrite(filename, traj,  duration=0.1)


问题


面经


文章

微信
公众号

扫码关注公众号