| from datetime import datetime, timedelta |
| import json |
| import numpy as np |
| from pathlib import Path |
| from EnumParkingStatus import EnumParkingStatus |
| import os |
| from AbstractFinalFileGenerator import AbstractFinalFileGenerator |
|
|
| class PLdsFinalFileGenerator(AbstractFinalFileGenerator): |
| def __init__(self, pathRootDataset, loadOriginalSpaces = False): |
| super().__init__(pathRootDataset, loadOriginalSpaces) |
|
|
| self.get_basename = False |
|
|
| def _buildOriginalFileReader(self): |
| return list() |
|
|
| def _loadJsonsNewAnnotations(self): |
| pathJsons = Path(self.pathRootDataset).rglob('*.json') |
| pathJsons = [x for x in pathJsons if x.is_file()] |
| for path in pathJsons: |
| with open(path, 'r') as file: |
| json_dict = json.load(file) |
| |
| |
| |
| |
| |
|
|
| img_id = int(str(path).split('_')[-1].split('.')[0]) |
| self.dictNewAnnots[img_id] = json_dict |
| self.orderedDictKeys.append(img_id) |
| self.orderedDictKeys.sort() |
| for x in self.orderedDictKeys: |
| print(x) |
|
|
| def _getDateFromFileName(self, fileName): |
| strDate = fileName[:] |
| strDate = strDate.split('/')[-2] |
| splitDate = strDate.split('-') |
| date = datetime(int(splitDate[0]),int(splitDate[1]),int(splitDate[2])) |
| return date |
|
|
| def _loadOriginalParkingSpacesAnnotations(self, imgFileName, imgId, annotations_start_id): |
| listDicts = [] |
| parkingSpaces, statuses = self.originalFileReader.readAllParkingSpacesInfo(imgFileName) |
|
|
| for i in range(len(statuses)): |
| dict = self._createDefaultDictParkingSpace(imgId,annotations_start_id) |
| spaces = [] |
| for coord in parkingSpaces[i]: |
| spaces.extend(coord) |
| dict["segmentation"] = spaces |
| dict["parking_status_id"] = statuses[i] |
|
|
| annotations_start_id += 1 |
| listDicts.append(dict) |
|
|
| return listDicts |
|
|
| def _loadNewParkingSpaces(self, imgFileName, imgId, annotations_start_id): |
| |
| img_id = int(imgFileName.split('_')[-1].split('.')[0]) |
| listDicts = [] |
|
|
| if img_id not in self.orderedDictKeys: |
|
|
| dict_keys = sorted(list(self.dictNewAnnots.keys())) |
| annotated_img_id = dict_keys.pop(-1) |
|
|
| while dict_keys and annotated_img_id > img_id: |
| annotated_img_id = dict_keys.pop(-1) |
|
|
| img_id = annotated_img_id |
|
|
| if img_id in self.orderedDictKeys: |
| spaces = self.dictNewAnnots[img_id] |
| for space in spaces: |
| resh = np.reshape(space, -1).tolist() |
| dict = self._createDefaultDictParkingSpace(imgId, annotations_start_id) |
| dict["segmentation"] = resh |
| dict["parking_status_id"] = EnumParkingStatus.UNKNOWN.value |
|
|
| annotations_start_id += 1 |
| listDicts.append(dict) |
|
|
| return listDicts |