Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

Commit

Permalink
Update to V4.2.0
Browse files Browse the repository at this point in the history
Option to enable / disable the AnalogReadout via Config.ini
  • Loading branch information
jomjol committed Dec 7, 2019
1 parent 28bb23a commit 29d08e5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Config_Description.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Options for ErrorReturn are the following:
* `ErrorMessage` = attach to value a reason for the inconistent value (max rate or negative)
* `Readout` = attach the original readout - usefull, if the OldValue is given back to see, what the readout really was

## Enable/Disable AnalogReadOut
#### Main section [AnalogReadOut]
Enable or disable the readout of the analog counter.
| Parameter | Meaning | Example |
| ------------- | ------------- | ------------- |
| Enabled | Diable or Enable the read out of the analog counters | `Enabled=True` or `Enabled=False` |


## Alignment
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This repository is the sum of different projects to read out an analog water met
The result is a HTTP-server, that takes an image as input, processes it and gives as an output the water meter number, including the subdigits.

## Changelog - lastest version
##### 4.2.0 (2019-12-07)
* Reading of analog counters is enabled or disabled via config.ini **special thanks to alikanarya**
##### 4.1.1 (2019-11-29)
* Error correction in ReadDigitalDigitClass.py
##### 4.1.0 (2019-11-25)
Expand Down
4 changes: 4 additions & 0 deletions code/config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ ErrorReturn=OldValue, ErrorMessage, Readout
#ErrorReturn=NewValue, ErrorMessage


[AnalogReadOut]
#If enabled analog counters will be read, if disabled only digital counters will be read.
Enabled=False

[alignment]
initial_rotation_angle=180

Expand Down
10 changes: 10 additions & 0 deletions code/lib/CutImageClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def __init__(self):
self.ref1 = cv2.imread(self.reference_image1)
self.ref2 = cv2.imread(self.reference_image2)

self.AnalogReadOutEnabled = True
if config.has_option('AnalogReadOut', 'Enabled'):
self.AnalogReadOutEnabled = config['AnalogReadOut']['Enabled']
if self.AnalogReadOutEnabled.upper() == 'FALSE':
self.AnalogReadOutEnabled = False


zw_Analog_Counter = config.get('Analog_Counter', 'names').split(',')
self.Analog_Counter = []
Expand Down Expand Up @@ -101,6 +107,10 @@ def Cut(self, image):
zeiger = self.cutZeiger(target)
ziffern = self.cutZiffern(target)

zeiger = ziffern
if self.AnalogReadOutEnabled:
zeiger = self.cutZeiger(target)

return [zeiger, ziffern]

def cutZeiger(self, source):
Expand Down
70 changes: 52 additions & 18 deletions code/lib/ZaehlerstandClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ def __init__(self):
config.read('./config/config.ini')

print('Start Init Zaehlerstand')
self.readAnalogNeedle = lib.ReadAnalogNeedleClass.ReadAnalogNeedle()
print('Analog Model Init Done')

self.AnalogReadOutEnabled = True
if config.has_option('AnalogReadOut', 'Enabled'):
self.AnalogReadOutEnabled = config['AnalogReadOut']['Enabled']
if self.AnalogReadOutEnabled.upper() == 'FALSE':
self.AnalogReadOutEnabled = False

if self.AnalogReadOutEnabled:
self.readAnalogNeedle = lib.ReadAnalogNeedleClass.ReadAnalogNeedle()
print('Analog Model Init Done')
else:
print('Analog Model Disabled')

self.readDigitalDigit = lib.ReadDigitalDigitClass.ReadDigitalDigit()
print('Digital Model Init Done')
self.CutImage = lib.CutImageClass.CutImage()
Expand Down Expand Up @@ -53,11 +64,17 @@ def setPreValue(self, setValue):
zerlegt = setValue.split('.')
vorkomma = zerlegt[0][0:len(self.CutImage.Digital_Digit)]
self.LastVorkomma = vorkomma.zfill(len(self.CutImage.Digital_Digit))
nachkomma = zerlegt[1][0:len(self.CutImage.Analog_Counter)]
while len(nachkomma) < len(self.CutImage.Analog_Counter):
nachkomma = nachkomma + '0'
self.LastNachkomma = nachkomma
result = 'Last value set to: ' + self.LastVorkomma + '.' + self.LastNachkomma

result='N'
if self.AnalogReadOutEnabled:
nachkomma = zerlegt[1][0:len(self.CutImage.Analog_Counter)]
while len(nachkomma) < len(self.CutImage.Analog_Counter):
nachkomma = nachkomma + '0'
self.LastNachkomma = nachkomma
result = 'Last value set to: ' + self.LastVorkomma + '.' + self.LastNachkomma
else:
result = 'Last value set to: ' + self.LastVorkomma

return result

def getROI(self, url):
Expand All @@ -76,12 +93,20 @@ def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = Fals
txt, logtime = self.LoadFileFromHTTP.LoadImageFromURL(url, './image_tmp/original.jpg')

if len(txt) == 0:
print('Start CutImage, AnalogReadout, DigitalReadout')
if self.AnalogReadOutEnabled:
print('Start CutImage, AnalogReadout, DigitalReadout')
else:
print('Start CutImage, DigitalReadout')
resultcut = self.CutImage.Cut('./image_tmp/original.jpg')
resultanalog = self.readAnalogNeedle.Readout(resultcut[0], logtime)

resultanalog = 0
if self.AnalogReadOutEnabled:
resultanalog = self.readAnalogNeedle.Readout(resultcut[0], logtime)
resultdigital = self.readDigitalDigit.Readout(resultcut[1], logtime)

self.akt_nachkomma = self.AnalogReadoutToValue(resultanalog)
self.akt_nachkomma = 0
if self.AnalogReadOutEnabled:
self.akt_nachkomma = self.AnalogReadoutToValue(resultanalog)
self.akt_vorkomma = self.DigitalReadoutToValue(resultdigital, UsePreValue, self.LastNachkomma, self.akt_nachkomma)
self.LoadFileFromHTTP.PostProcessLogImageProcedure(True)

Expand All @@ -100,28 +125,37 @@ def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = Fals
zw = str(int(resultdigital[i]))
txt += '<img src=/image_tmp/'+ str(resultcut[1][i][0]) + '.jpg></img>' + zw
txt = txt + '<p>'
txt = txt + 'Analog Meter: <p>'
for i in range(len(resultanalog)):
txt += '<img src=/image_tmp/'+ str(resultcut[0][i][0]) + '.jpg></img>' + "{:.1f}".format(resultanalog[i])
txt = txt + '<p>'
if self.AnalogReadOutEnabled:
txt = txt + 'Analog Meter: <p>'
for i in range(len(resultanalog)):
txt += '<img src=/image_tmp/'+ str(resultcut[0][i][0]) + '.jpg></img>' + "{:.1f}".format(resultanalog[i])
txt = txt + '<p>'
print('Get Zaehlerstand done')
return txt

def MakeReturnValue(self, error, errortxt, single):
output = ''
if (error):
if self.ErrorReturn.find('Value') > -1:
output = str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma)
output = str(self.akt_vorkomma.lstrip("0"))
if self.AnalogReadOutEnabled:
output = output + '.' + str(self.akt_nachkomma)
if not single:
output = output + '\t' + self.akt_vorkomma + '\t' + self.akt_nachkomma
output = output + '\t' + self.akt_vorkomma
if self.AnalogReadOutEnabled:
output = output + '\t' + self.akt_nachkomma
if len(output) > 0:
output = output + '\t' + errortxt
else:
output = errortxt
else:
output = str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma)
output = str(self.akt_vorkomma.lstrip("0"))
if self.AnalogReadOutEnabled:
output = output + '.' + str(self.akt_nachkomma)
if not single:
output = output + '\t' + self.akt_vorkomma + '\t' + self.akt_nachkomma
output = output + '\t' + self.akt_vorkomma
if self.AnalogReadOutEnabled:
output = output + '\t' + self.akt_nachkomma
return output

def UpdateLastValues(self, error):
Expand Down

0 comments on commit 29d08e5

Please sign in to comment.