Can't get to exif data .JPG image - python-3.x

I'm trying to read the exif data from a .JPG image. I've tried differents solutions found here and there (PIL, piexif, exifread...) and none of them worked for this set of images. It worked for other images taken from another camera but not for this one, all these different methods returning empty dictionaries. It seems that there is no exif data but (I apologies for my newbyness) when I RIGHT-click + properties (I use windows), I do see what is exif data to me : date of creation, etc...
Here is one image :
image.JPG
If another of the thousands of anonymous heroes could help me on this one, I would be very grateful...

Alright so I found a solution which I share now.
The problem is that the libraries that open metadata are not taking all possible configurations for the image file and therefore, they can handle some and some others they cannot. I finally made it using exiftool, an executable that I dowloaded on my windows on this link :
https://sno.phy.queensu.ca/~phil/exiftool/
Then I paste the executable in a folder and I add exiftool.py in that folder, that I got from :
https://github.com/smarnach/pyexiftool/find/master
Then, using this small piece of code (for example):
import exiftool
with exiftool.ExifTool("exiftool.exe") as et:
metadata = et.get_metadata_batch(files)
for d in metadata:
print("{:20.20} {:20.20}".format(d["SourceFile"],
d["File:FileCreateDate"]))
Of course, this is just to show that you indeed can access the metadata, then you can do whatever you want with that. Here is the documentation of the library exiftool : http://smarnach.github.io/pyexiftool/
Cheers, JM

Related

PySide6: fail to load "jpg" format in QPixmap

I'm trying to load "jpg" picture on the QLabel in PySide6. So I used this:
mypic = QPixmap()
mypic.load("./test.jpg")
self.ui.mylabel.setPixmap(QPixmap(mypic))
However, I found there is empty in mylabel. When I debug in this program, I found that my pic is null (even after it loads the image file).
So I wonder if the jpg is not automatically supported in PySide6.
As I checked the documention of PySide6, it illustrates that the default supporting image formats include "jpg".
enter image description here
As I print the supportedImageFormats using:
print(QtGui.QImageReader.supportedImageFormats())
It returns with this:
[PySide6.QtCore.QByteArray(b'bmp'), PySide6.QtCore.QByteArray(b'pbm'), PySide6.QtCore.QByteArray(b'pgm'), PySide6.QtCore.QByteArray(b'png'), PySide6.QtCore.QByteArray(b'ppm'), PySide6.QtCore.QByteArray(b'xbm'), PySide6.QtCore.QByteArray(b'xpm')]
I found it does not include the "jpg" format by default!
Then I searched a lot of solutions, I found that this can solve my problem: add one line of code to introduce the "imageformats" plugins in PySide6 folder.
app.addLibraryPath(os.path.join(os.path.dirname(QtCore.__file__), "plugins"))
Here I printed the os.path.dirname(QtCore.__file__), and found it was my PySide6 folder.
I checked the plugins folder, and found the inner imageformats folder, and found these dlls:
enter image description here
It seems that the jpg format is supported here. So when I add the plugin path, it can solve my problem. But it still confuses me that why I should add the plugin path (The official documentation implies that this format is supported by default!).
I wonder if there is a more convincing solution because adding one line of code in my program every time seems clumsy. Or if I left out something. I sincerely want to get your help. Thank you!

Use images in s3 with SageMaker without .lst files

I am trying to create (what I thought was) a simple image classification pipeline between s3 and SageMaker.
Images are stored in an s3 bucket with their class labels in their file names currently, e.g.
My-s3-bucket-dir
cat-1.jpg
dog-1.jpg
cat-2.jpg
..
I've been trying to leverage several related example .py scripts, but most seem to be download data sets already in .rec format or containing special manifest or annotation files I don't have.
All I want is to pass the images from s3 to the SageMaker image classification algorithm that's located in the same region, IAM account, etc. I suppose this means I need a .lst file
When I try to manually create the .lst it doesn't seem to like it and it also takes too long doing manual work to be a good practice.
How can I automatically generate the .lst file (or otherwise send the images/classes for training)?
Things I read made it sound like im2rec.py was a solution, but I don't see how. The example I'm working with now is
Image-classification-fulltraining-highlevel.ipynb
but it seems to download the data as .rec,
download('http://data.mxnet.io/data/caltech-256/caltech-256-60-train.rec')
download('http://data.mxnet.io/data/caltech-256/caltech-256-60-val.rec')
which just skips working with the .jpeg files. I found another that converts them to .rec but again it has essentially the .lst already as .json and just converts it.
I have mostly been working in a Python Jupyter notebook within the AWS console (in my browser) but I have also tried using their GUI.
How can I simply and automatically generate the .lst or otherwise get the data/class info into SageMaker without manually creating a .lst file?
Update
It looks like im2py can't be run against s3. You'd have to completely download everything from all s3 buckets into the notebook's storage...
Please note that [...] im2rec.py is running locally,
therefore cannot take input from the S3 bucket. To generate the list
file, you need to download the data and then use the im2rec tool. - AWS SageMaker Team
There are 3 options to provide annotated data to the Image Classification algo: (1) packing labels in recordIO files, (2) storing labels in a JSON manifest file ("augmented manifest" option), (3) storing labels in a list file. All options are documented here: https://docs.aws.amazon.com/sagemaker/latest/dg/image-classification.html.
Augmented Manifest and .lst files option are quick to do since they just require you to create an annotation file with a usually quick for loop for example. RecordIO requires you to use im2rec.py tool, which is a little more work.
Using .lst files is another option that is reasonably easy: you just need to create annotation them with a quick for loop, like this:
# assuming train_index, train_class, train_pics store the pic index, class and path
with open('train.lst', 'a') as file:
for index, cl, pic in zip(train_index, train_class, train_pics):
file.write(str(index) + '\t' + str(cl) + '\t' + pic + '\n')

Perl reading XLSX embeded documents

First post here so if I am doing something stupid, please let me know.
CentOS 7(3.10.0-123.6.3.el7.x86_64), perl5 (revision 5 version 16 subversion 3), Spreadsheet::ParseXLSX v0.16
I have an .xlsx that has some embedded .pdf's and another xlsx in embedded within it. I am trying to read these and insert them into a csv along with the original xlsx. After some googl'ing to no avail my thought was to unzip the original xlsx and read the files from the xl/embeddings directory but, alas there is something with the file that causes adobe reader to not be able to read the oleObject(X).bin files in that dir.
I have been able to successfully read all the worksheets that dio not contain embedded docs using Spreadsheet::ParseXLSX, works great. I have googled for a solution but am either not using correct search prams or ...
If you know how to do this can you point me to some instructions?
TIA,
JohnM

Magento: "Image does not exist"

I'm importing a CSV file in Magento (version 1.9).
I receive the error: 'Image does not exist'.
I've tried to do everything I could find on the internet.
The template I'm using for upload is the default template taken from my export folder.
I've added the / before the image name and I've also saved the file as UTF-8 format.
Any advice would help.
Use advanced profiler
System > Import/Export > Dataflow – Profiles
You only need to include the attributes that are required, which is just the SKU. Plus the appropiate image attributes. Plus labels if you want to go all out.
When you are creating your new profile, enter the following settings:
Now you can hit save! With our Profile now complete, we just need to create the folder media/import. This is where you will be storing all your images awaiting import.
When uploading images, they need to be within a folder called media/import. Once saved to that folder you can then reference them relatively. By that I mean if your image is in media/import/test.jpg in your csv reference it as /test.jpg. It’s as easy as that.
Please check this link for more information
Import products using csv
in the Default Import
first move all the images in media/import folder and then use '/imagename' in csv and then import.
And give the 777 permission to the import folder.
Let me know if you have any query....
check 3 point before upload csv file in Magento
create media > import folder and place all images inside import
folder import folder should have 777 permission
the path of images should be /desert-002.jpg
It may issue with image path in CSV if a image path in CSV is abg/test.jpg then it path in Dir is ..media/import/abg/test.jpg.also check image extension letter issue. Suppose your image extension I'd JPG and you rewrite in CSV is jpg .then it show image not exits
Your file template must look like this:
sku,image
product-001,/product_image.jpg
This file must exist: yourdocroot/media/import/product_image.jpg
More detail please read this method:
Mage_Catalog_Model_Convert_Adapter_Product::saveImageDataRow
You will see these lines:
$imageFile = trim($importData['_media_image']);
$imageFile = ltrim($imageFile, DS);
$imageFilePath = Mage::getBaseDir('media') . DS . 'import' . DS . $imageFile;
I hope this help!!!

How can I rename all the existing carrierwave uploaded files?

I have been using Carrierwave for file uploads for some time. I did not try to rename the files as they got uploaded. Now I want to give each file a random name and a file extension that's consistent with the content type. I read the wiki and other sites, and it was recommended that in the uploader, I could:
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
private
def secure_token
#implement the secure token
end
It worked fine on files uploaded after these additions to the uploader. But I got many files that were uploaded before this change. I was wondering if someone could tell me how to migrate the old files.
I tried adding a method to the uploader:
def rename_file!
model.update_attribute mounted_as, "#{secure_token}.#{file.extension}"
recreate_versions!
end
then in the rails console, I tried calling this on an model with attachment. However, I found that the mounted_as column of the model never got updated, though on the file system, various versions of the file were created with the new name. When I inspected the mounted_as field of the model, it did not get updated. The log actually said the column was updated with the old value.
How can I get the mounted_as column on the model updated?
In addition, it seemed like the old files with the old names were still on the file system. Is there a way to remove them? I tried adding a line:
file.move_to File.join("#{File.dirname file.path}, "#{secure_token}.#{file.extension}")
in the rename_file! method. It renamed the files, but did not update the mounted_as column on the model. So accessing its URL resulted in a 404.
I know this is a little old now, but perhaps useful for others.
After updating your Uploader with the filename method, like you have, you could run this from the Rails console;
Post.all.each do |p|
p.avatar.recreate_versions!
p.save!
end
In the current version of CarrierWave, this will both rename the file and update the model record.
Post of course is the model name and avatar the column on which you are mounting the uploader, so change those as required.

Resources