Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to randomly select some of the extracted frames #1

Open
stathdim opened this issue Dec 12, 2019 · 2 comments
Open

Script to randomly select some of the extracted frames #1

stathdim opened this issue Dec 12, 2019 · 2 comments

Comments

@stathdim
Copy link
Collaborator

This script should utilize the frames naming pattern (string+number.jpg) to make selection easier.
We can simple generate a random number from 1 till (number of frames) and select the corresponding frame. Afterwards the generated number is stored in a selected_frames list. Then for each number we generate we check if the frame was already selected

@stathdim
Copy link
Collaborator Author

@stathdim
Copy link
Collaborator Author

stathdim commented Dec 12, 2019

import os

os.chdir('videos/')

def readFilenames(): 
    files = set()
    with os.scandir('.') as entries:
        for entry in entries:
            filename = entry.name.split('.')[0]
            files.add(filename)
    return files

# Each filename must be unique to avoid processing the same file twice
files = readFilenames()

# Read all files and strip the extension 
# We use just the filename title to avoid having to if-else about the extensions
with os.scandir('.') as entries:
    for entry in entries:
        filename = entry.name.split('.')[0]
        files.add(filename)

The code above is can be used as a blueprint for reading the images from the filesystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant