File size: 3,085 Bytes
07444d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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")