Code Monkey home page Code Monkey logo

Comments (1)

heinrich-heine avatar heinrich-heine commented on June 26, 2024 2

Hi, I wrote a simple script to apply on gif files:

#open the cricket shot video under data/ and convert it into a npy array of shape (1, num_frames, 224, 224, 3)

from PIL import Image
from PIL import GifImagePlugin
import numpy as np
import os
import re
import shutil

#delete the folder test_files
shutil.rmtree('test_files', ignore_errors=True)
#create new empty one
os.mkdir('test_files')

#select the .gif
imageObject = Image.open('data/dog.gif')

print(imageObject.is_animated)

print(imageObject.n_frames)

Display individual frames from the loaded animated GIF file

for frame in range(0,imageObject.n_frames):

imageObject.seek(frame)
image_name = frame
resized_im = imageObject.resize((224,224))

resized_im.save('test_files/' + str(frame) + '.png')

#get the filenames with os
file_list = os.listdir('test_files/')
#sort maybe that matters

#to not take ds store

#ONLY needed when .DS store file in the dir, if craeted newly by script--> no .DS
#file_list = file_list[1:]

file_list.sort(key=lambda f: int(re.sub('\D', '', f)))

#pipeline which can be easily adapted for my data in image files

#base of stack
pic = Image.open('test_files/0.png')
pic = pic.convert('RGB')
pix = np.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3)
video_array = np.reshape(pix, (1, 224, 224,3))

for file in range(1,len(file_list)):

pic = Image.open('test_files/' + file_list[file])
pic = pic.convert('RGB')
pix = np.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3)
pix = np.reshape(pix, (1, 224, 224,3))

#stack all frame arrays or better concatenate
video_array = np.concatenate((video_array, pix))

def convert_pixel_value(pixel_value):

converted = ((pixel_value-128)/128) * 1
    
return converted

video_array = convert_pixel_value(video_array)

frames = (np.shape(video_array))[0]

np.save('data/input_array.npy', video_array)

video_array = np.reshape(video_array, (1, frames, 224, 224, 3))

from keras-kinetics-i3d.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.