-
Notifications
You must be signed in to change notification settings - Fork 23
/
Interface.py
155 lines (143 loc) · 4.82 KB
/
Interface.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import json
import os
import cv2
from Algorithm.absorb import absorb
from Algorithm.Blenometer import checkBleno
from Algorithm.SF6 import SF6Reader
from Algorithm.oilTempreture import oilTempreture
from Algorithm.videoDigit import videoDigit
from Algorithm.arrest.countArrester import countArrester
from Algorithm.arrest.doubleArrester import doubleArrester
from Algorithm.pressure.digitPressure import digitPressure
from Algorithm.pressure.normalPressure import normalPressure
from Algorithm.pressure.colorPressure import colorPressure
from Algorithm.onoff.onoffIndoor import onoffIndoor
from Algorithm.onoff.onoffOutdoor import onoffOutdoor
from Algorithm.onoff.onoffBatteryScreen import onoffBattery
from Algorithm.onoff.readyStatus import readyStatus
from Algorithm.onoff.springStatus import springStatus
from Algorithm.onoff.contactStatus import contactStatus
from Algorithm.others.colordetect import colordetect
from Algorithm.others.Cabinet_indicator import indicatorimg
from Algorithm.others.Knob_status import knobstatus
from configuration import *
def meterReaderCallBack(image, info):
"""call back function"""
if info["type"] == None:
return "meter type not support!"
else:
return info["type"](image, info)
def getInfo(ID):
"""
get info from file
:param ID: meter ID
:return: info = {
"distance": 10,
"horizontal": 10,
"vertical": 20,
"name": "1_1",
"type": SF6,
"template": "template.jpg",
"ROI": {
"x": 200,
"y": 200,
"w": 1520,
"h": 680
},
"startPoint": {
"x": -1,
"y": -1
},
"endPoint": {
"x": -1,
"y": -1
},
"centerPoint": {
"x": -1,
"y": -1
},
"startValue": 0,
"totalValue": 2
}
"""
file = open(configPath + "/" + ID + ".json")
info = json.load(file)
# string to pointer
if info["type"] == "absorb":
info["type"] = absorb
elif info["type"] == "digitPressure":
info["type"] = digitPressure
elif info["type"] == "normalPressure":
info["type"] = normalPressure
elif info["type"] == "contact":
info["type"] = contactStatus
elif info["type"] == "colorPressure":
info["type"] = colorPressure
elif info["type"] == "SF6":
info["type"] = SF6Reader
elif info["type"] == "countArrester":
info["type"] = countArrester
elif info["type"] == "doubleArrester":
info["type"] = doubleArrester
elif info["type"] == "oilTempreture":
info["type"] = oilTempreture
elif info["type"] == "blenometer":
info["type"] = checkBleno
elif info["type"] == "onoffIndoor":
info["type"] = onoffIndoor
elif info["type"] == "onoffOutdoor":
info["type"] = onoffOutdoor
elif info["type"] == "onoffBattery":
info["type"] = onoffBattery
elif info["type"] == "videoDigit":
info["type"] = videoDigit
elif info["type"] == "ready":
info["type"] = readyStatus
elif info["type"] == "spring":
info["type"] = springStatus
elif info["type"] == "colordetect":
info["type"] = colordetect
elif info["type"] == "cabinetindicator":
info["type"] = indicatorimg
elif info["type"] == "Knob":
info["type"] = knobstatus
else:
info["type"] = None
info["template"] = cv2.imread(templatePath + "/" + ID + ".jpg")
if info["digitType"] != "False":
info.update(json.load(open(os.path.join("ocr_config", info["digitType"] + ".json"))))
return info
def meterReader(recognitionData, meterIDs):
"""
global interface
:param recognitionData: image or video
:param meterIDs: list of meter ID
:return:
"""
# results = {}
results = []
for i, ID in enumerate(meterIDs):
# get info from file
info = getInfo(ID)
if info["digitType"] == "VIDEO":
results[ID] = meterReaderCallBack(recognitionData, info)
else:
# ROI extract
x = info["ROI"]["x"]
y = info["ROI"]["y"]
w = info["ROI"]["w"]
h = info["ROI"]["h"]
# call back
# cv2.rectangle(recognitionData, (x, y), (x+w, y + h), (255, 0, 0), 3)
# cv2.imshow("testInput", recognitionData)
# cv2.waitKey(0)
if x != 0 or y != 0 or w != 0 or h != 0:
ROI = recognitionData[y:y + h, x:x + w]
else:
ROI = recognitionData
try:
results.append(meterReaderCallBack(ROI, info))
except AttributeError:
print("Error in ", ID)
results = [0]
return results