Load image folder data set using name - python

I have a folder for image data set , and I wanna load this folder to be a training data set using python this image of my folder and it`s images

If there's only one directory then you can use os.listdir() or if you want to lookup recursively then look up os.walk().

Related

Iterate through a folders and subfolders?

Say I have a folder named people. Inside that folder there are subfolders person_1, person_2, person_3, etc. Each person_# subfolder contains an image of a smiling face (person_1_happy.png) and frowning face (person_1_sad.png).
Is there a succinct way to use python to iteratively run through each folder and grab only the person_#_face images?

Want to compile all the images in a folder and its subfolders to pdf file with names

I am just a beginner in Python. So help me learn and write the code for a small but complex problem. I've tried many things but I am lost where to start with and go:
Problem:
I have a folder and its subfolders with heaps of different product images(let's say in .jpeg and .png). I want to compile a single pdf of all these photos with links/location of these photos in the pdf. This list and photos could be in the form of a table or a very simple format.
I am doing it because sometimes I forget the product name so I have to look at its image by going into each folder and sub-folder. This will give me an opportunity to look at all the photos in these folders and sub-folder without opening them one-by-one.
Your issue breaks down into 3 steps.
1-Search the directories for files (which you can use the os module's walk()).
here is a great tutorial:
https://www.pythoncentral.io/how-to-traverse-a-directory-tree-in-python-guide-to-os-walk/
2-add the found files into a list of tuples having path of the image and the name of it.
3- Add these images into a single pdf file. You can use python module fpdf to do this. And this has been addressed already here:
Create PDF from a list of images

How to load image using pygame.image.load()?

I just want to know the syntax. How do I load an image using pygame.image.load() ?
Let's take an example, I want to load an image called cat.png - and type this
pygame.image.load('cat.png')
Then, where should the image cat.png be saved?
By default, Python only searches in your current directory for files, however, if you wish to load images from a separate directory, you may find this useful:
Importing images from a directory (Python)
For the syntax, I reccomend you refer to the documentation, here:
https://www.pygame.org/docs/ref/image.html#pygame.image.load
pygame.image.load()ΒΆ
load new image from a file
load(filename) -> Surface
load(fileobj, namehint="") -> Surface
Load an image from a file source. You can pass either a filename or a Python file-like object.
Any images loaded directly with
pygame.image.load('Image Name')
should be saved in the same folder as the python script that is using the image

How to export file to another place with the same hierarchy in python?

I want to do the following thing:
Get all the images in a directory (include the images in subdirectory), do something with them (for example: resize), then export these images to another directory with the same hierarchy.
For example:
I want to get images from input/flower/rose, resize it and export to output, ask python to automatically create the hierarchy flower/rose inside output.
How can I do that?
os.makedirs will recreate the directory hierarchy if you use e.g.
os.makedirs("output/flower/rose")

Django-filer: How to create folders and save uploaded images correctly?

The django-filer documentation makes no mention of how to correctly create folder and save the images savely inside.
My scenario:
I have different users that can upload images through the frontend. Right now every FilerImage I create gets saved in the unspecified folder. How do I create a folder for every user programmatically?
And how do I move the uploaded FilerImage instance in code without violating the private/public settings of the file?
Here is a solution I found out through fiddling around. It is very possible, that this is not the prgmatic way to handle this!
#Import Folder model
from filer.models.foldermodels import Folder
#Create Folder:
folder = Folder(owner=someuser, name="myname") #owner is required
folder.save()
#Create Subfolder
subfolder = Folder(owner=someuser, name="subfolder", parent=folder)
subfolder.save()
More onfo can be gained by looking inside the Source-Code of the Folder Model, here.

Categories

Resources