How to Read Picasa 3.9 Database and extract faces data

How to Read Picasa 3.9 Database and extract faces data

Retrieving information from Picasa is not an easy thing, the software is quite limited and hardly offers any data export function.

What I would like to do: extract the raw face recognition information from the Picasa database. I need the person names, the image filename and the rectangle associated with each face.

On Windows 7, the Picasa database is located in C:\Users\USERNAME\AppData\Local\Google\Picasa2. In this folder, we can found mainly pmp and db files. The pmp files store tabular data. Each PMP file contains a column of a table in the database. The name of the file is table_column.pmp. The Picasa database contains 3 tables:

albumdata, which contains information on the albums (folders and face album)
catdata, categories data (almost empty on my computer)
imagedata, images data (includes rectangles and references albums)

How to read PMP files ?

PMP files are binary files in little-endian format. The header is described by the following table :

Size Description
4 bytes magic constant : 0x3fcccccd
2 bytes field type (unsigned short)
2 bytes constant: 0x1332
4 bytes constant: 0x00000002
2 bytes field type (unsigned short)
2 bytes constant: 0x1332
4 bytes number of entries (unsigned int)

The field-type values are :

Value Description
0x0 null-terminated strings
0x1 Unsigned int, 4 bytes
0x2 Dates, Microsoft Variant Time format, 8 bytes
0x3 byte field, 1 byte
0x4 unsigned long, 8 bytes
0x5 unsigned short, 2 bytes
0x6 null-terminated strings
0x7 unsigned int, 4 bytes

See http://sbktech.blogspot.fr/2011/12/picasa-pmp-format.html for more information on pmp files.

The interesting values for faces are facerect (rectangle coordinates) and personalbumid (album reference) in the table imagedata, and the values token (album reference) and name (person name) in the table albumdata.

Example (keeping only 4 columns):

Extract from the table imagedata from Picasa 3.9

Extract from the table imagedata from Picasa 3.9

The rectangle is described by a value in the format rectangle64. A 64 bit number breakable in 4 16-bit numbers. The 4 numbers, once divided by 2^16-1 (the maximum value), are the relative coordinates of the top left corner and the bottom right corner. The absolute values can be obtained by multiplying the values by the width and height of the picture.

Example :

original number (64 bits) 0x67873bec9e1e933d
Break in 4 16-bit number 0x6787 0x5678 0x3b51 0x4a89
Convert to decimal 26503 15340 40478 37693
Divide by 2^16-1 (65535) 0,4044 0,2341 0,6176 0,5751
Multiply by the width (3264) and the height (2448) x1=1319 y1=573 x2=2016 y2=1407

With those information, we know that the image x has a rectangle corresponding to a specific person but we don’t know yet the file name of the picture.

This information is held in the file thumbindex.db. This file contains the whole list of folders and files indexed inside the Picasa database. the line x in thumbindex.db file will correspond to the same image as the line x in the table imagedata.

How to read thumbindex.db ?

Header :

Size Description
4 bytes magic constant: 0x40466666
4 bytes number of entries (unsigned int)

And each line follows this schema:

Size Description
until null character null-terminated strings
26 bytes useless content
4 bytes index

A line will be either a folder with its complete path and a specific index value (4294967295), or an image with its filename and an index value pointing to the parent folder.

Extract from the file thumbindex.db from Picasa 3.9

Extract from the file thumbindex.db from Picasa 3.9

In this example the image 266 is in the folder 5.

See http://projects.mindtunnel.com/picasa3meta/docs/picasa3meta.thumbindex.ThumbIndex-class.html for more information on the  thumbindex.db file.

If we merge the table imagedata and the data from thumbindex.db, for a specific image, we have the filename, the face rectangle but no album reference to associate the face to a person!

Picasa will actually add a virtual image to store this information. In the previous example, the virtual picture 268 (which has no filename) is linked to the image 266 and will contain information on the face of one person (1 virtual image per person). The rectangle in the image 266 will contain all face rectangles present in the image (when the image has more than one face identified, otherwise the rectangle will be the same as the one of the single person). So, we just need to read the reference album of the image 268 and associate it with the image file 266.

I have created a software that parse all those information and store them in csv files. One file per table pmp and one file for the faces. If imagemagick is installed (and the convert application is in the path), the software can create thumbshots of all the faces.

How to use the program to parse Picasa database ?

There are in fact 2 programs, one called PMPDB that will convert the pmp tables into csv files and one called PicasaFaces that will create a nice human readable csv with all the face information and the face thumbshots.

Usage:

java -classpath ".:bin/:commons-cli-1.2.jar" PMPDB -folder "/path/to/PicasaDB/Picasa2/db3/" -output ./OutputFolder

java -classpath ".:bin/:commons-cli-1.2.jar:commons-io-2.4.jar" PicasaFaces -folder "/path/to/PicasaDB/Picasa2/db3/" -output ./OutputFolder -replaceRegex C: -replacement /media/HardDrive -convert /path/to/convert(.exe)

If the command line contains the argument -convert, then imagemagick will create all the face thumbshots (in the output folder with a folder for each person). A string replacement of the original image paths can be done if the pictures location is different from the database (in the example “C:” will be replaced by “/media/HardDrive”).

Result from the face data extraction

Result from the face data extraction

source are available on github : https://github.com/skisoo/PicasaDBReader

Working on Windows and Linux.

The 2013 General Election in Malaysia seen by taxi drivers

The 2013 General Election in Malaysia seen by taxi drivers

A few days back, I went to Malaysia for a short business trip. Out of curiosity I asked all my taxi drivers what they thought of the coming elections. A quick summary of the situation, the 5th May 2013 will be the General Election for Malaysia where Malaysians will vote for a new government. The current ruling party, the Barisan Nasional, has been the same since the independence of Malaysia, some 56 years ago. The current government had been increasingly challenged and seemed to show real signs of anxiety. For the first time, this election sees a possible chance of switching government.

Flags in every street from all political parties

Flags in every street from all political parties

First driver, Malay

He does not like the current Prime Minister as well as the wife who has a reputation of a spendthrift. He told me that this is the first Prime Minister that has created an office of the First Lady (FLOM), which was strongly criticized. He is fully aware that the current government’s willingness to give money to the people (1000RM for all employees of Petronas, student aid, book vouchers, senior citizen financial aid) under the guise of economic struggles has a political purpose. He also criticized the fact that members of the Barisan Nasional have easier access to housing. He would like changes in the current political landscape.

Second driver, Indian

He criticized the government by saying that the Barisan Nasional lies to the people, using the people’s money for their own benefit. The current climate is not healthy for minority races (Chinese and Indian) which leads to brain drain as more non-Malay Malaysians students are moving away to foreign country. He finds that even the Malays complain of lost business opportunities because they are not members of Barisan Nasional and he is also aware of the political purpose behind the cash handouts. For him, the opposition has little chance of winning the elections but there is a chance the Barisan Nasional could lose the majority in the parliament.

Third driver, Malay (living in a small village 60km from Kuala Lumpur renting a house for 300RM per month)

He is satisfied with the current government. He finds that the economic situation is good and dynamic and people have what they need.

Fourth driver, Indian

He thinks that people are far from stupid and they can vote for whoever they want, although they have received money from Barisan Nasional and seeing flags put up everywhere. A practice that he finds ridiculous, it is not the number of flags that will influence the voters. He is not really convinced by the political strength of the opposition which is a collaboration of three parties with divergence. He particularly fears the radical Islamic party that wants to turn Malaysia into an Islamic country. He is satisfied with the current Prime Minister, who is doing his job correctly (as opposed to a previous Minister). He thinks that the Barisan Nasional will win the elections.

Fifth driver, Indian

He thinks the current government gives a lot of scholarships to Malay students while Chinese or Indian students with good academic results struggle to have one. For housing, he told me that the Barisan Nasional negotiates with developers a 7 – 15% discount for Malay who wants to buy a home, else the project is not approved. He also fears radical Islamic party in the opposition.

The amazing view from the Pinnacle at Duxton

The amazing view from the Pinnacle at Duxton

It’s been a long time I wanted to go for to the top of Pinnacle, a very recent and classy HDB that has little to envy to condominiums except for a pool and a gym, but I never took the time to go. Why go to this HDB in particular? Because of its skybridge! A huge bridge that connects the seven buildings together on the fiftieth floor. My company just moved in the neighborhood and I have a new camera to test, so I had no excuse to postpone my visit anymore.

Just after work, I hurried to go there to try to get the sunset. I went to Building G to find the terminal that would took $5 from my transport card, the visitor price to the skybridge (it’s free for residents). I turned around 10 minutes before finally finding this terminal on the ground floor (that look more like a basement). Then, elevator to the top floor and a tinny tourniquet to access skybrigde.

What can be seen from the Pinnacle skybrigde?

  • The huge port of Singapore (between Marina Bay and Harbour Front)
  • The back CBD (compared to classic photos taken from the esplanade)
  • Sentosa Island, the cable car and mount Faber
  • The new Singapore Cruise Terminal
  • Chinatown with its temple and its shop houses
  • Outram Park
  • The petrochemical facilities
  • The West
The port of Singapore

The port of Singapore

The new Singapore Cruise Terminal

The new Singapore Cruise Terminal

Chinatown and its temple

Chinatown and its temple

Singapore skyline at night

Singapore skyline at night

 

Future Music Festival Asia, music concert in Kuala Lumpur

Future Music Festival Asia, music concert in Kuala Lumpur

The Future Music Festival Asia (FMFA) was my second music concert of the year, and it was much more impressive than the first one! Future Music Festival is originally a festival taking place in Australia’s five largest cities (Sydney, Melbourne, Brisbane, Perth and Adelaide) a few days apart, usually in early March with the same line-up. Since 2012, the festival was exported to Asia in Kuala Lumpur on the Sepang International Circuit with a different list of artists. Some of the headliners for the 2013 Asian show were namely The Prodigy, Fun., Rita Ora, PSY …

How did it go?

Well, a bit of a hassle when we tried to find a place to park with the incredible number of cars (the festival was located an hour drive from Kuala Lumpur and there wasn’t much public transport to go there). We had to go pretty far into the deep end of the parking area and walk a good 15 minutes to reach the entrance of the Future Music Festival Asia.

Balloons floating in the sky

Balloons floating in the sky

Once at the entrance, we bought some beers – twice cheaper than in the festival, to cool down a little bit, then we passed three checks (age, bags and tickets) before finally getting into the festival. First impression: it’s Huge! Three big stages, a brightly and colorfully lit Ferris wheel and an interesting number of food stalls and entertainment area: cigarettes, F1 Grand Prix promotion booths for the upcoming race on the 22 – 24 March 2013 (with video games), Red Bull, illuminated balloons floating in the sky (I did not really understand the purpose of it) … In short, a lot of things to occupy thousands of people for a long night.

Fun. at Future Music Festival Asia

Fun. at Future Music Festival Asia

And for the show itself? Crazy, wild and hyped-up night, loud beats and music along with well-known artists which got  the spectators jumping, dancing and moving all night! Honestly, I did not really know all the artists, just what was on air on the radio but it was really great! I was surprised by the large number of non-Asian people that was present at the concerts, mainly Australian and a lot of people coming from Singapore according to the reception given to a Singaporean flag holder.

The second stage

The second stage

The ferris wheel and the impressive public

The ferris wheel and the impressive public

Future Music Festival Asia was also the last city of PSY’s world tour for his “Gangnam Style” and he chose to immortalize it by singing his song twice: once for everyone to take photos and videos (We are in Asia after all!) and one second time for everyone to dance!

Tweet From PSY

Tweet From PSY

PSY at Future Music Festival Asia

PSY at Future Music Festival Asia

Sentosa Flowers or how to start the year of the snake with flowers

Sentosa Flowers or how to start the year of the snake with flowers

You like flowers and you do not know what to do during this long weekend in Singapore with more than half of the stores closed? Go enjoy the beautiful flowers scattered along Palawan Beach in Sentosa Island. The event is from 9 to 17 February for the modest price of $ 5. The visit of the flowers is quite fast but it feels good to walk on the beach without any purpose.

A snake is hidden in this photo

A snake is hidden in this photo

I don't know what kind of bird is it but I like the idea

I don’t know what kind of bird is it but I like the idea

Bucolic scene with flowers

Bucolic scene with flowers

The pumpkin chariot

The pumpkin chariot

A star flower

A star flower

Sandy snake

Sandy snake

Nuwa

Nuwa

flowers at sentosa

flowers at sentosa

A little boat ride in a pond

A little boat ride in a pond

A colorul and flowery snake

A colorul and flowery snake

A bit of French soft power in South Korea

A bit of French soft power in South Korea

During a business trip in South Korea, just when I came back from lunch, I was surprised to see “C’est pas sorcier” a famous French educational television program on MBC, a Korean TV channel. Korean soft power has considerably increased in recent years culminating with Gangnam style but I never imagined that a French TV program such as this one could be exported to the country of Kimchi and awesome educational animations (unless I mixed up with Japan). The French influence in Asia is generally limited to LVMH, food and coffee shops: Paris baguette, Paul…

"C'est pas sorcier" in Korean

“C’est pas sorcier” in Korean