acatalano
Posts: 19
Joined: Mon Jun 22, 2015 1:49 pm
Location: Boulder, CO USA
Contact: Website

picamera and EXIF Tags-Solved

Sat Jan 04, 2020 5:52 pm

picamera does not natively embed the EXIF tags for exposure time and iso settings. The picamera documentation does give an example to embed text, but not the actual values for these settings into the image.jpg file. I have tried various lines of code to do this such as

Code: Select all

 camera.exif_tags['EXIF.ExposureTime'] = camera.exposure_speed
but these just generate mmal errors. Can anyone provide examples of the proper python syntax to embed the various camera settings into the EXIF tags?

(note:corrected the missing quotes around EXIF...)
Last edited by acatalano on Thu Jan 09, 2020 4:40 pm, edited 1 time in total.
Anthony Catalano, PhD
Boulder, CO USA
Weather Station & Webcams at:
www.boulderwx.com
www.boulderweather.org

User avatar
scruss
Posts: 2814
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: picamera and EXIF Tags

Sat Jan 04, 2020 7:08 pm

Looking at the exif_tags docs, it looks like you need to pass the tag name as a string. So maybe this will work:

Code: Select all

camera.exif_tags['EXIF.ExposureTime'] = camera.exposure_speed
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

acatalano
Posts: 19
Joined: Mon Jun 22, 2015 1:49 pm
Location: Boulder, CO USA
Contact: Website

Re: picamera and EXIF Tags

Sat Jan 04, 2020 9:20 pm

Yes I know. It was an oversight on my part that I did not write it out correctly, just from memory (which is imperfect!). I have tried putting it in a string. Sort of a bummer that this data is not encoded in the jpg by default.

(corrected the oversight in the original post)
Last edited by acatalano on Thu Jan 09, 2020 4:41 pm, edited 1 time in total.
Anthony Catalano, PhD
Boulder, CO USA
Weather Station & Webcams at:
www.boulderwx.com
www.boulderweather.org

acatalano
Posts: 19
Joined: Mon Jun 22, 2015 1:49 pm
Location: Boulder, CO USA
Contact: Website

Re: picamera and EXIF Tags-SOLVED

Thu Jan 09, 2020 3:13 pm

Solved the problem simply using PIL. The exif data is present when the image is captured, it's just not saved. I noticed as the file was being created the exif data appeared briefly in the file manager on the mounted windows computer (Directory Opus shows the exif file data) where the file is saved. But then it disappeared in the saved image! So I then used PIL's Image save function to capture the exif data as show below after adding some overlays to the image.

Code: Select all

 camera.capture(image_name, format='jpeg',quality=100)
                       
 #Open image file
 image = Image.open(image_name)
          .
 #write stuff on image then:            
 image.save(image_name, exif=image.info["exif"], quality=100)
Last edited by acatalano on Thu Jan 09, 2020 4:46 pm, edited 1 time in total.
Anthony Catalano, PhD
Boulder, CO USA
Weather Station & Webcams at:
www.boulderwx.com
www.boulderweather.org

User avatar
scruss
Posts: 2814
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: picamera and EXIF Tags

Thu Jan 09, 2020 4:46 pm

Neat! That looks like it'll be loading and re-encoding the JPEG, though. You won't be losing much with quality=100, but the re-encoding processing is likely something you'd want to avoid. A library like exif might save that modification step.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
paddyg
Posts: 2463
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: picamera and EXIF Tags-Solved

Thu Jan 09, 2020 9:44 pm

Yes, @scruss is probably right. I think I wouldn't save the image but capture to numpy array then convert to PIL Image. I don't know if that will then have exif editing available (or if it's tied up with jpeg). I check it out later if I get chance.

Paddy

PS I think reading the exif info is a lazy operation i.e. the full file isn't read into memory until you try to use an Image function that requires it. Writing is probably a different kettle of fish.

PPS After a quick look I would say writing exif info onto a PIL Image created from numpy array isn't trivial. I think Pillow has plans to introduce more exif functionality in the future but at the moment probably better to use another module - assuming there turn out to be problems using the method you've already got working!
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”