{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Import error\n", "\n", "```\n", "!pip install pip install EXCAT-Sync\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import matplotlib.image as mpimg\n", "import matplotlib.patches as patches\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from exact_sync.v1.api.annotations_api import AnnotationsApi\n", "from exact_sync.v1.api.images_api import ImagesApi\n", "from exact_sync.v1.api.image_sets_api import ImageSetsApi\n", "from exact_sync.v1.api.annotation_types_api import AnnotationTypesApi\n", "\n", "from exact_sync.v1.models import ImageSet, Team, Product, AnnotationType, Image, Annotation, AnnotationMediaFile\n", "from exact_sync.v1.rest import ApiException\n", "from exact_sync.v1.configuration import Configuration\n", "from exact_sync.v1.api_client import ApiClient" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set user name, password and server address" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "configuration = Configuration()\n", "configuration.username = 'Video'\n", "configuration.password = 'VideoMaker'\n", "configuration.host = \"http://127.0.0.1:8000\"\n", "\n", "client = ApiClient(configuration)\n", "\n", "image_sets_api = ImageSetsApi(client)\n", "annotations_api = AnnotationsApi(client)\n", "annotation_types_api = AnnotationTypesApi(client)\n", "images_api = ImagesApi(client)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'creator': 4,\n", " 'description': None,\n", " 'id': 182,\n", " 'images': [1522],\n", " 'location': None,\n", " 'main_annotation_type': None,\n", " 'name': 'EXACT-Sync',\n", " 'path': 'exact_116_182',\n", " 'product_set': [{'annotationtype_set': [{'area_hit_test': True,\n", " 'closed': True,\n", " 'color_code': '#FF0000',\n", " 'default_height': 50,\n", " 'default_width': 50,\n", " 'enable_blurred': False,\n", " 'enable_concealed': False,\n", " 'id': 313,\n", " 'name': 'Dog',\n", " 'node_count': 0,\n", " 'product': 151,\n", " 'sort_order': 0,\n", " 'vector_type': 1},\n", " {'area_hit_test': True,\n", " 'closed': True,\n", " 'color_code': '#0000FF',\n", " 'default_height': 50,\n", " 'default_width': 50,\n", " 'enable_blurred': False,\n", " 'enable_concealed': False,\n", " 'id': 314,\n", " 'name': 'Cap',\n", " 'node_count': 0,\n", " 'product': 151,\n", " 'sort_order': 1,\n", " 'vector_type': 1}],\n", " 'creator': 4,\n", " 'description': '',\n", " 'id': 151,\n", " 'imagesets': [182],\n", " 'name': 'Dog',\n", " 'team': 116}],\n", " 'set_tags': [],\n", " 'team': 116}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image_set = image_sets_api.retrieve_image_set(id=182, expand=\"product_set,product_set.annotationtype_set\")\n", "image_set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download the image" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{WindowsPath('examples/images/20200910_191741.png'): {'annotations': [1310630, 1310631],\n", " 'filename': '20200910_191741.tiff',\n", " 'height': 4032,\n", " 'id': 1522,\n", " 'image_set': 182,\n", " 'image_type': 0,\n", " 'mpp': 0.0,\n", " 'name': '20200910_191741.png',\n", " 'objective_power': 1.0,\n", " 'time': datetime.datetime(2020, 11, 1, 11, 46, 17, 901497),\n", " 'width': 1908}}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "target_folder = Path('examples/images/') \n", "target_folder.mkdir(parents=True, exist_ok=True)\n", "\n", "images = {}\n", "image_id = 0\n", "\n", "for image_id in image_set.images:\n", " image_id = image_id\n", " image = images_api.retrieve_image(id=image_id)\n", " \n", " name = image.name\n", " image_path = target_folder/name\n", "\n", " # if file not exists download it\n", " if image_path.is_file() == False:\n", " images_api.download_image(id=image_id, target_path=image_path, original_image=True)\n", " \n", " images[image_path] = image\n", " \n", "images" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Donwload annotations" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'count': 2,\n", " 'next': None,\n", " 'previous': None,\n", " 'results': [{'annotation_type': 313,\n", " 'annotationversion_set': [],\n", " 'blurred': None,\n", " 'concealed': None,\n", " 'deleted': None,\n", " 'description': None,\n", " 'id': 1310630,\n", " 'image': 1522,\n", " 'last_edit_time': None,\n", " 'last_editor': None,\n", " 'meta_data': None,\n", " 'time': None,\n", " 'unique_identifier': None,\n", " 'uploaded_media_files': [],\n", " 'user': None,\n", " 'vector': {'frame': 1,\n", " 'x1': 216,\n", " 'x2': 1405,\n", " 'y1': 1121,\n", " 'y2': 3331},\n", " 'verified_by_user': None},\n", " {'annotation_type': 314,\n", " 'annotationversion_set': [],\n", " 'blurred': None,\n", " 'concealed': None,\n", " 'deleted': None,\n", " 'description': None,\n", " 'id': 1310631,\n", " 'image': 1522,\n", " 'last_edit_time': None,\n", " 'last_editor': None,\n", " 'meta_data': None,\n", " 'time': None,\n", " 'unique_identifier': None,\n", " 'uploaded_media_files': [],\n", " 'user': None,\n", " 'vector': {'frame': 1,\n", " 'x1': 345,\n", " 'x2': 1328,\n", " 'y1': 765,\n", " 'y2': 1278},\n", " 'verified_by_user': None}]}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "annotations = annotations_api.list_annotations(image=image_id, fields=\"annotation_type,id,image,vector\")\n", "annotations" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | id | \n", "type | \n", "image | \n", "vector | \n", "
|---|---|---|---|---|
| 0 | \n", "1310630 | \n", "313 | \n", "1522 | \n", "{'x1': 216, 'x2': 1405, 'y1': 1121, 'y2': 3331... | \n", "
| 1 | \n", "1310631 | \n", "314 | \n", "1522 | \n", "{'x1': 345, 'x2': 1328, 'y1': 765, 'y2': 1278,... | \n", "