| from pathlib import Path |
| import json |
| from ImgLabels import ImgLabels |
| |
|
|
| class Checker: |
| def __init__(self, rootJsons): |
| self.root = rootJsons |
| pathJSons = Path(rootJsons).rglob('*.json') |
| self.data = [] |
| for path in pathJSons: |
| print('Loading ', path) |
| with open(path, 'r') as read_file: |
| self.data.append(json.load(read_file)) |
|
|
| |
| def check(self,rootImages): |
| |
| dictImgId = {} |
| dictImgsLabels = {} |
| allPaths = [] |
| inexistentFiles = [] |
| if self.root[-1] != '/': |
| self.root += '/' |
| for dict in self.data: |
| pathImgs = Path(rootImages).rglob('*.jpg') |
| for path in pathImgs: |
| new_path = str(path).replace(self.root, '') |
| allPaths.append(new_path) |
| |
| |
|
|
| allPaths = list(set(allPaths)) |
| print(len(allPaths), 'images found in the entire dataset') |
| for js in self.data: |
| print(len(js['images']), 'images in', js['images'][0]['subset']) |
| for imgData in js['images']: |
| imgPath = imgData['file_name'] |
| |
| |
| |
| allPaths.remove(imgPath) |
| coords = imgData ['annotationsRectangle'] |
| dictImgId[imgData['id']] = (imgPath, (coords[0], coords[1]), (coords[0]+coords[2], coords[1]+coords[3])) |
| |
| |
|
|
| |
| for mask in js['annotations']: |
| imgId = mask['image_id'] |
| |
| path = (dictImgId[imgId])[0] |
| if path in dictImgsLabels: |
| dictImgsLabels[path].masks.append(mask['segmentation']) |
| else: |
| dictImgsLabels[path] = ImgLabels(masks = [mask['segmentation']], occupiedRRs = [], |
| emptyRRs = [], unknownRRs = [], annotationsRectangleP1 = (dictImgId[imgId])[1], annotationsRectangleP2 = (dictImgId[imgId])[2]) |
| |
| |
| |
| for ps in js['parkingSpots']: |
| imgId = ps['image_id'] |
| |
| path = (dictImgId[imgId])[0] |
| rr = ps['rotatedRect'] |
| if ps['status_id'] == 1: |
| dictImgsLabels[path].emptyRRs.append(rr) |
| else: |
| if ps['status_id'] == 2: |
| dictImgsLabels[path].occupiedRRs.append(rr) |
| else: |
| dictImgsLabels[path].unknownRRs.append(rr) |
| |
| |
| return dictImgsLabels, allPaths, inexistentFiles |