2022-2023/1NSI/10_Dictionnaire/2E_exif_folium.ipynb

535 lines
10 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "437fa01c",
"metadata": {},
"source": [
"# Métadonnées d'une image\n",
"\n",
"Dans ce TP, vous allez manipuler les métadonnées d'images pour ensuite les placer sur une carte.\n",
"\n",
"## Extraction des métadonnées\n",
"\n",
"Pour manipuler les images, on a besoin d'une librairie de manipulation d'images."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c9c7e32",
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image, ExifTags"
]
},
{
"cell_type": "markdown",
"id": "960941d7",
"metadata": {},
"source": [
"Vous venez d'importer deux modules qui vous permettrons de manipuler des images et les metadonnées (les tags exifs).\n",
"\n",
"### Image\n",
"\n",
"Pour importer une image"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc05608c",
"metadata": {},
"outputs": [],
"source": [
"image1 = Image.open(\"image1.jpg\")\n",
"image1"
]
},
{
"cell_type": "markdown",
"id": "28e7d3fe",
"metadata": {},
"source": [
"Pour obtenir les données exifs on pourra utiliser la méthode `._getexif()` sur l'image."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75ad9d0a",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"image1._getexif()"
]
},
{
"cell_type": "markdown",
"id": "8bddb206",
"metadata": {},
"source": [
"Quel type de données est utilisé pour stocker les données exifs?"
]
},
{
"cell_type": "raw",
"id": "7fb64ce8",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "4b9c1b9e",
"metadata": {},
"source": [
"Quelles sont les informations que l'on peut trouver dans les métadonnées d'une image?"
]
},
{
"cell_type": "raw",
"id": "7211efe2",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "f6496594",
"metadata": {},
"source": [
"Quels problèmes a-t-on pour comprendre ce dictionnaire?"
]
},
{
"cell_type": "raw",
"id": "c1ea645c",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "356814cc",
"metadata": {},
"source": [
"### Comprendre les données exifs\n",
"\n",
"Pour donner un sens aux clés du dictionnaire des données exifs, le module `ExifTags` a un attribut `.TAGS`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04a8f787",
"metadata": {},
"outputs": [],
"source": [
"ExifTags.TAGS"
]
},
{
"cell_type": "markdown",
"id": "545f1db5",
"metadata": {},
"source": [
"Quel est ce type de données?"
]
},
{
"cell_type": "raw",
"id": "d5ede170",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "a7564aaa",
"metadata": {},
"source": [
"À quelle caractéristique correspond la clé `34853`?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00d8d07d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9b695442",
"metadata": {},
"source": [
"À quelle caractéristique correspond la clé `272`?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3d05add",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "1eb8842b",
"metadata": {},
"source": [
"À quelle caractéristique correspond la clé `306`?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ff2023d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b14e7a73",
"metadata": {},
"source": [
"Faire une boucle sur les données exifs de l'`image1` en affichant la description de la donnée et la donnée. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99f357bc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "95afa782",
"metadata": {},
"source": [
"Ecrire une fonction `extrait_exit` qui prend en argument une image et qui renvoie un dictionaire contenant les données exifs (avec le clés qui doivent être la description de la donnée)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce958419",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "96fb0759",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3b677187",
"metadata": {},
"source": [
"### Données GPS\n",
"\n",
"On s'interesse plus précisement aux données GPS de l'image.\n",
"\n",
"Afficher les données `'GPSInfo'` de l'`image1`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5b901411",
"metadata": {},
"outputs": [],
"source": [
"image1._getexif()[34853]"
]
},
{
"cell_type": "markdown",
"id": "033a1730",
"metadata": {},
"source": [
"Quel type est utilisé pour stocker les données GPS?"
]
},
{
"cell_type": "raw",
"id": "086ee50f",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "322a9278",
"metadata": {},
"source": [
"Quel est le type des clés?"
]
},
{
"cell_type": "raw",
"id": "a140e2fd",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "f4f06f4c",
"metadata": {},
"source": [
"Pour donner un sens à ces clés, le module `ExifTags` a un attibut `GPSTAGS` pour leur donner un sens."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e13b29a0",
"metadata": {},
"outputs": [],
"source": [
"ExifTags.GPSTAGS"
]
},
{
"cell_type": "markdown",
"id": "732ece8c",
"metadata": {},
"source": [
"Ecrire une fonction `extrait_gps` qui prend en argument une image et qui renvoie un dicitonnaire avec les données GPS (avec des clés compréhensibles)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dbd0945a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a282a17",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "77ecc152",
"metadata": {},
"source": [
"La longitude et la latitude sont données sous forme de tuple (degré, minute, secondes).\n",
"\n",
"Pour les transformer en forme décimale, vous pouvez utiliser la fonction suivante"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0d9ca0f",
"metadata": {},
"outputs": [],
"source": [
"def gps_to_degre(gps:tuple) -> float:\n",
" \"\"\"Converti des données GPS en notation décimale\n",
" \n",
" :param gps: tuple de données GPS (degré, minute, secondes)\n",
" :return: gps en décimal\n",
" \n",
" :example:\n",
" >>> gps_to_degre((48.0, 50.0, 44.85))\n",
" 48.84579166666667\n",
" \n",
" \"\"\"\n",
" return gps[0] + gps[1]/60 + gps[2]/3600"
]
},
{
"cell_type": "markdown",
"id": "1d3726cd",
"metadata": {},
"source": [
"Ecrire une fonction `ajoute_degre` qui prend en argument un dictionnaire contenant toutes les données gps et qui renvoie ces données où l'on a ajouté les clés `degreLattitude` et `degreLongitude` (calculés avec la fonction `gps_to_degre`)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3e048d8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "02fc0400",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "bbe16539",
"metadata": {},
"source": [
"Extraire les données GPS des images \n",
"\n",
"- `image2.jpg`\n",
"- `image3.jpg`\n",
"- `image4.jpg`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e6348e6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ccb0bb48",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "27e2647c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "66c525f8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "2b0004af",
"metadata": {},
"source": [
"## Folium\n",
"\n",
"Folium est une librairie qui permet de manipuler des cartes."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4e23b6c",
"metadata": {},
"outputs": [],
"source": [
"from folium import Map, Marker"
]
},
{
"cell_type": "markdown",
"id": "ad5694a8",
"metadata": {},
"source": [
"Créer une carte"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5822416",
"metadata": {},
"outputs": [],
"source": [
"carte = Map(location=[45.5236, -122.6750])\n",
"marqueur = Marker(location=[45.5236, -122.6750])\n",
"marqueur.add_to(carte)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ce827c7",
"metadata": {},
"outputs": [],
"source": [
"carte"
]
},
{
"cell_type": "markdown",
"id": "e8ca713b",
"metadata": {},
"source": [
"À quoi correspond la liste de nombres passés en argument de la fonction `Map` ou de `Marker`?"
]
},
{
"cell_type": "raw",
"id": "281f1e36",
"metadata": {},
"source": [
" "
]
},
{
"cell_type": "markdown",
"id": "21c54fff",
"metadata": {},
"source": [
"À vous de géolocaliser les images suivantes:\n",
"\n",
"- `image1.jpg`\n",
"- `image2.jpg`\n",
"- `image3.jpg`\n",
"- `image4.jpg`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae1323d6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}