1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-28 08:58:49 +02:00

Adding test to exiftool based face region parsing

This commit is contained in:
Patrik J. Braun 2020-12-27 14:35:30 +01:00
parent f2538410f6
commit d00cf9420e
4 changed files with 93 additions and 37 deletions

View File

@ -210,45 +210,52 @@ export class MetadataLoader {
const faces: FaceRegion[] = []; const faces: FaceRegion[] = [];
if (ret.Regions && ret.Regions.value.RegionList && ret.Regions.value.RegionList.value) { if (ret.Regions && ret.Regions.value.RegionList && ret.Regions.value.RegionList.value) {
for (let i = 0; i < ret.Regions.value.RegionList.value.length; i++) { for (let i = 0; i < ret.Regions.value.RegionList.value.length; i++) {
if (ret.Regions.value.RegionList.value[i].value &&
ret.Regions.value.RegionList.value[i].value['rdf:Description'] && let type, name, box;
ret.Regions.value.RegionList.value[i].value['rdf:Description'].value && const regionRoot = ret.Regions.value.RegionList.value[i] as any;
ret.Regions.value.RegionList.value[i].value['rdf:Description'].value['mwg-rs:Area']) { const createFaceBox = (w: string, h: string, x: string, y: string) => {
const region = ret.Regions.value.RegionList.value[i].value['rdf:Description']; return {
const regionBox = ret.Regions.value.RegionList.value[i].value['rdf:Description'].value['mwg-rs:Area'].attributes; width: Math.round(parseFloat(w) * metadata.size.width),
if (region.attributes['mwg-rs:Type'] !== 'Face' || height: Math.round(parseFloat(h) * metadata.size.height),
!region.attributes['mwg-rs:Name']) { left: Math.round(parseFloat(x) * metadata.size.width),
continue; top: Math.round(parseFloat(y) * metadata.size.height)
}
const name = region.attributes['mwg-rs:Name'];
const box = {
width: Math.round(parseFloat('' + regionBox['stArea:w']) * metadata.size.width),
height: Math.round(parseFloat('' + regionBox['stArea:h']) * metadata.size.height),
left: Math.round(parseFloat('' + regionBox['stArea:x']) * metadata.size.width),
top: Math.round(parseFloat('' + regionBox['stArea:y']) * metadata.size.height)
}; };
// convert center base box to corner based box };
box.left = Math.max(0, box.left - box.width / 2);
box.top = Math.max(0, box.top - box.height / 2); /* Adobe Lightroom based face region structure*/
faces.push({name: name, box: box}); if (regionRoot.value &&
} else if((ret.Regions.value.RegionList.value[i] as any).Area && regionRoot.value['rdf:Description'] &&
(ret.Regions.value.RegionList.value[i] as any).Name && regionRoot.value['rdf:Description'].value &&
(ret.Regions.value.RegionList.value[i] as any).Type) { regionRoot.value['rdf:Description'].value['mwg-rs:Area']) {
const regionBox = (ret.Regions.value.RegionList.value[i] as any).Area.value;
const name = (ret.Regions.value.RegionList.value[i] as any).Name.value; const region = regionRoot.value['rdf:Description'];
const type = (ret.Regions.value.RegionList.value[i] as any).Type.value; const regionBox = region.value['mwg-rs:Area'].attributes;
if (type !== 'Face') continue;
const box = { name = region.attributes['mwg-rs:Name'];
width: Math.round(parseFloat(regionBox.w.value) * metadata.size.width), type = region.attributes['mwg-rs:Type'];
height: Math.round(parseFloat(regionBox.h.value) * metadata.size.height), box = createFaceBox(regionBox['stArea:w'],
left: Math.round(parseFloat(regionBox.x.value) * metadata.size.width), regionBox['stArea:h'],
top: Math.round(parseFloat(regionBox.y.value) * metadata.size.height) regionBox['stArea:x'],
}; regionBox['stArea:y']);
// convert center base box to corner based box /* Load exiftool edited face region structure, see github issue #191 */
box.left = Math.max(0, box.left - box.width / 2); } else if (regionRoot.Area && regionRoot.Name && regionRoot.Type) {
box.top = Math.max(0, box.top - box.height / 2);
faces.push({name: name, box: box}); const regionBox = regionRoot.Area.value;
name = regionRoot.Name.value;
type = regionRoot.Type.value;
box = createFaceBox(regionBox.w.value,
regionBox.h.value,
regionBox.x.value,
regionBox.y.value);
} }
if (type !== 'Face' || !name) {
continue;
}
// convert center base box to corner based box
box.left = Math.max(0, box.left - box.width / 2);
box.top = Math.max(0, box.top - box.height / 2);
faces.push({name: name, box: box});
} }
} }
if (Config.Client.Faces.keywordsToPersons && faces.length > 0) { if (Config.Client.Faces.keywordsToPersons && faces.length > 0) {

View File

Before

Width:  |  Height:  |  Size: 889 KiB

After

Width:  |  Height:  |  Size: 889 KiB

View File

@ -0,0 +1,42 @@
{
"cameraData": {
"ISO": 160,
"exposure": 0.0008,
"fStop": 5.6,
"focalLength": 85,
"lens": "EF-S15-85mm f/3.5-5.6 IS USM",
"make": "Canon",
"model": "Canon EOS 600D"
},
"creationDate": 1434116432000,
"faces": [
{
"box": {
"height": 626,
"left": 374.5,
"top": 353,
"width": 669
},
"name": "Alvin the Squirrel"
}
],
"fileSize": 909930,
"keywords": [
"USA",
"Yosemite"
],
"orientation": 1,
"positionData": {
"GPSData": {
"altitude": 1960,
"latitude": 37.746765,
"longitude": -119.52988333333333
},
"country": "United States",
"state": "California"
},
"size": {
"height": 1132,
"width": 1697
}
}

View File

@ -32,6 +32,13 @@ describe('MetadataLoader', () => {
}); });
it('should load jpg edited with exiftool', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/exiftool.jpg'));
const expected = require(path.join(__dirname, '/../../../assets/exiftool.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
it('should load mp4', async () => { it('should load mp4', async () => {
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video.mp4')); const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video.mp4'));
const expected = require(path.join(__dirname, '/../../../assets/video.json')); const expected = require(path.join(__dirname, '/../../../assets/video.json'));