| from enum import Enum |
| from pathlib import Path |
| import numpy as np |
| import cv2 |
|
|
| from IntermediateFile import IntermediateFile |
| from NewPolygonsDrawer import NewPolygonsDrawer |
| from XMLPKLotReader import XMLPKLotReader |
| from EnumKeys import EnumKeys |
|
|
| class AbstractControllerInterface(): |
| PRINT_ID = 0 |
| def __init__(self, rootOriginalDataset): |
| self.root = rootOriginalDataset |
| self.drawer = self.createPolygonsDrawer() |
| self.idx_image = 0 |
| self.intermediateFilesHandler = IntermediateFile() |
|
|
| self.pathsArray = [] |
| pathImgs = Path(self.root).rglob('*.jpg') |
| for path in pathImgs: |
| path_str = str(path) |
| key = path_str.split("/")[-1].split(".")[0] |
| self.pathsArray += [{'key': key, 'path': path_str}] |
|
|
| self.pathsArray = sorted(self.pathsArray, key=lambda x: x['key']) |
|
|
| def begin(self): |
| self.printInstructions() |
|
|
| self.updateImage() |
| self.drawer.run() |
|
|
| def keysCheck(self): |
| key = cv2.waitKey(25) |
|
|
| if self.checkNonStandardKeys(key): |
| return |
|
|
| if key == EnumKeys.EXIT: |
| self.drawer.stop() |
| return |
|
|
| if key == EnumKeys.MODE_SEL: |
| self.drawer.selectionMode() |
| return |
|
|
| if key == EnumKeys.NEXT_IMAGE: |
| self.nextImage() |
| return |
|
|
| if key == EnumKeys.PREV_IMAGE: |
| self.prevImage() |
| return |
|
|
| if key == EnumKeys.SAVE_PRINT: |
| self.savePrint() |
| return |
|
|
| if key == EnumKeys.INCREASE_BRIGHTNESS: |
| self.drawer.extra_brightness = self.drawer.extra_brightness + 10 |
| print("Current brightness", self.drawer.extra_brightness) |
| return |
| |
| if key == EnumKeys.DECREASE_BRIGHTNESS: |
| self.drawer.extra_brightness = self.drawer.extra_brightness - 10 |
| if self.drawer.extra_brightness < 0: |
| self.drawer.extra_brightness = 0 |
| print("Current brightness", self.drawer.extra_brightness) |
| return |
|
|
| def updateImage(self): |
| raise NotImplementedError("Abstract Class") |
|
|
| def nextImage(self): |
| if self.idx_image == len(self.pathsArray) - 1: |
| return |
| self.idx_image = self.idx_image + 1 |
| self.updateImage() |
| return |
|
|
| def prevImage(self): |
| if self.idx_image == 0: |
| return |
| self.idx_image = self.idx_image - 1 |
| self.updateImage() |
| return |
|
|
| def savePrint(self): |
| AbstractControllerInterface.PRINT_ID = AbstractControllerInterface.PRINT_ID + 1 |
| output = self.root + "/print" + str(AbstractControllerInterface.PRINT_ID) + ".png" |
| cv2.imwrite(output, self.drawer.canvas) |
| print("Print saved: " + output) |
| return |
|
|
| def createPolygonsDrawer(self): |
| raise NotImplementedError("Abstract Class") |
|
|
| def printInstructions(self): |
| raise NotImplementedError("Abstract Class") |
|
|
| def checkNonStandardKeys(self, key): |
| raise NotImplementedError("Abstract Class") |
|
|