Welcome Guest Search | Active Topics | Members | Log In | Register
How To: Modify metadata extraction from media objects Options
Roger Martin
Posted: Friday, May 02, 2008 11:01:27 AM
Rank: Administration

Joined: 8/3/2007
Posts: 847
Location: Fort Atkinson, WI
Gallery Server Pro extracts several well-known properties from images such as width, height, camera maker, etc. However, there are hundreds of potential properties to choose from, and you may want to view some that are not currently being extracted. Here are instructions for modifying the source code to extract additional metadata items or change how current ones are extracted.

The metadata extraction is done in the file/class MediaObjectMetaDataExtractor.cs in the project TIS.GSP.Business. Metadata are extracted when an object is first added to the gallery and when a synchronization is performed when the "Re-import metadata" option is selected. Metadata are extracted in two basic steps:

1. Raw metadata are extracted from the image and stored in an internal dictionary named _rawMetadata.

2. A small subset of the raw metadata is extracted and formatted into user-friendly phrases, such as "3008 px" for width. This subset is returned by the GetGalleryObjectMetadataItemCollection method and assigned to a property on the Image class, where it is ultimately stored in the gs_MediaObjectMetadata table in the database.

Since all possible metadata will be extracted into the first step, all you have to do is format the raw data into a user-friendly format. The dictionary where the raw data is stored (_rawMetadata) is keyed by the enum RawMetadataItemName.

To convert the raw metadata into formatted values displayed in the web page, you need to add code to the function AddExifMetadata to pull out the raw data from _rawMetadata, format it, and add it to IGalleryObjectMetadataItemCollection parameter passed into the function. This will involve adding at least one item to an enumeration named FormattedMetadataItemName. For example, if you are extracting the altitude from the raw property GpsAltitude, you might add an enum item 'Altitude'.

Once you add the formatted value to the collection, you are done. It should automatically be persisted to the database and displayed in the metadata window.

If you discover that you want to display a metadata item that is not extracted into the _rawMetadata dictionary, boy I don't know what to tell you. It may not be possible with the .NET Framework, but you might have success if you reach into the Win32 classes.

Note: In addition to pulling data directly from the Exif data using the .NET 2.0 technique, if .NET 3.0 or 3.5 is installed, the MediaObjectMetaDataExtractor class gives priority to any metadata discovered via the new WPF classes. This happens in the class WpfMetadataExtractor in the project TIS.GSP.Business.Wpf. This code is invoked by the AddWpfBitmapMetadata function. If you are modifying one of the metadata items that are extracted from this function, you must edit the WpfMetadataExtractor class instead.

Hope this helps,

Roger Martin
Lead Developer for Gallery Server Pro
meigs
Posted: Saturday, May 03, 2008 5:45:38 AM
Rank: Advanced Member

Joined: 3/16/2008
Posts: 57
Location: Pennsylvania
Thanks for the very helpful post to understand the code better! A question from this:

Is there a unique identifier that is generated for a given photo or more generally any media object? It woudl be great to be able to uniquely associate the file with an unique ID, like a GUID, so that if the file name gets chanced it would be still possible to associate it with the database.

If there were something similar in photos that is used to create an (almost) unique key for an audio CD it would be easier to find duplicate photos in multiple directories. I am currently working to get a master set of photos from our family and I have discovered that many have been shared multiple times and so there are a lot of duplicates all with different file names due to local owners. I am using GSP to collect - now I am trying to figure out what is the same and what is different.

And, thanks again for a really great program. I am looking forward to the next release!!
Roger Martin
Posted: Saturday, May 03, 2008 8:19:40 AM
Rank: Administration

Joined: 8/3/2007
Posts: 847
Location: Fort Atkinson, WI
Each media object is identified by an ID property, and each record in the database stores the filename for each ID.

Each record also stores a hash key for each media object. This is a unique string generated from the file's name and its creation timestamp. My goal with this hash key was to try to independently identify a photo so that if, for example, the user used Windows Explorer to move the file from one directory to another, Gallery Server could link it back to the original caption (title) during the next synchronization.

But since the hash key is based in part on the filename, that won't help you identify duplicates with different names. What you needs is some kind of fingerprint of the image itself. It could be as simple as looking at the file size or as complicated as fingerprinting the image itself. Out of the box Gallery Server doesn't do this.

I am wondering if you could use something like Vista's Photo Gallery (or a similar program) to create a virtual folder of all your images. Then sort them by file size. Duplicate images will appear next to each other, making it easier to identify and (optionally) delete.

Hope this helps,


Roger Martin
Lead Developer for Gallery Server Pro
meigs
Posted: Saturday, May 03, 2008 8:36:13 AM
Rank: Advanced Member

Joined: 3/16/2008
Posts: 57
Location: Pennsylvania
Thanks. I dont know much about exif properties. Is it possible to have a user defined field where I could externally create and save a unique ID for a picture? If that is possible then I could do that for all my photos and then modify source code as described to pick up that ID for a given picture. thanks.
Roger Martin
Posted: Saturday, May 03, 2008 4:06:46 PM
Rank: Administration

Joined: 8/3/2007
Posts: 847
Location: Fort Atkinson, WI
I'm not sure if you can create your own EXIF property, but even if you could I wouldn't recommend it. It would be easier to use one of the existing properties such as title or description. If you use one of those Gallery Server will automatically extract it.

Note that Gallery Server won't let you write EXIF data; you'll have to find another program to do that.


Roger Martin
Lead Developer for Gallery Server Pro
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.2 (NET v2.0) - 9/27/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.