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

Commit

Permalink
Update to v3.0.0
Browse files Browse the repository at this point in the history
- Implementation of consistency check
  • Loading branch information
jomjol committed Oct 6, 2019
1 parent aa7c0c2 commit df79d7e
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Changelog
##### 3.0.0 (2019-10-06)
* Impementation of optional consistency check of readout value (not negative, maximum rate)
##### 2.3.0 (2019-10-05)
* Load default configuration, if none is present (beneficial for Docker-Version with mounted config and log directories)
* Parameter "simple" to reduche output to a single value
Expand Down
19 changes: 19 additions & 0 deletions Config_Description.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The config.ini file contains the information for the alignment and ROIs to process the image. It consists of 3 main segments, which are described in the following sections:

* `[Imagesource]`
* `[ConsistencyCheck]`
* `[alignment]`
* `[Analog_Counter]`
* `[Digital_Counter]`
Expand All @@ -22,6 +23,24 @@ The parameter `url=` in the server request can be omitted, if in the Imagesource
| LogImageLocation | optional - if set, the source images will be logged in the given folder | `LogImageLocation=./log/source_image` |
| LogOnlyFalsePictures | optional - if enabled, only false picture will be stored to avoid large amounts of pictures | `LogOnlyFalsePictures=True` |

## ConsistencyCheck
#### Main section [ConsistencyCheck]
Here a consistency check of the readout value with respect to the previous full read value can be configured. Prequisite is, that the previous value is stored and has no non readable digits ("N"). This can be achieved by using setPreValue to store the first value and the parameter &usePreValue to constantly remove the "N" in case of unambigous digits.

| Parameter | Meaning | Example |
| ------------- | ------------- | ------------- |
| Enabled | Diable or Enable the Check | `Enabled=True` |
| AllowNegativeRates | If set to `False`, then only increasing counter values are accepted | `AllowNegativeRates=False` |
| MaxRateValue | Maximum absolute change from the previous value (+/-) | `MaxRateValue=0.1` |
| ErrorReturn | Return value, in case of unconsistent values | `ErrorReturn=OldValue, ErrorMessage, Readout` |

Options for ErrorReturn are the following:
* `OldValue` = giving back the old value and ignore the "false" readout
* `NewValue` = notify about unconstent value, but still accept it and give it back as readout
* `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



## Alignment

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +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
##### 2.3.0 (2019-10-05)
* Load default configuration, if none is present (beneficial for Docker-Version with mounted config and log directories)
* Parameter "simple" to reduche output to a single value
##### 3.0.0 (2019-10-06)
* Impementation of optional consistency check of readout value (not negative, maximum rate)
### [Full Changelog](Changelog.md)


Expand All @@ -29,6 +28,9 @@ Path are relative, so it should run immediatly with the following command:
The configuration is storred in the subdirectory `config`. In the Ini-file the CNN-Network to be loaded is listed. Configuration of the neural network (*.h5) itself is stored in the subdirectory `neuralnets`.
Detailed information on config.ini see [Config_Description.md](Config_Description.md)

##### Consistency Check
With Version 3.0.0 a consistency check of the readout value is implemented. Prequesite for this check is a storage of the last full readout (without "N"), which can be achieved by the parameter "usePreValue".


## Running the server
Expand Down
14 changes: 14 additions & 0 deletions code/config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ LogImageLocation=./log/source_image
# Falls nur schlechte / fehlerhafte Bilder gelockt werden sollen, naechste Zeile Kommentar entfernen
#LogOnlyFalsePictures=True

[ConsistencyCheck]
Enabled=True
AllowNegativeRates=False
#Maximum Change of new to old value (+ or -)
MaxRateValue=0.1

#Return in Case of Error: Value = OldValue or NewValue
# ErrorMessage = Return Text with problem (seperated by Tabstopp) if nothing, then no error message
# Readout = Real Readout without corrections (NewValue)
ErrorReturn=OldValue, ErrorMessage, Readout
#ErrorReturn=OldValue, ErrorMessage
#ErrorReturn=NewValue, ErrorMessage


[alignment]
initial_rotation_angle=180

Expand Down
14 changes: 14 additions & 0 deletions code/config_default/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ LogImageLocation=./log/source_image
# Falls nur schlechte / fehlerhafte Bilder gelockt werden sollen, naechste Zeile Kommentar entfernen
#LogOnlyFalsePictures=True

[ConsistencyCheck]
Enabled=False
AllowNegativeRates=False
#Maximum Change of new to old value (+ or -)
MaxRateValue=0.1

#Return in Case of Error: Value = OldValue or NewValue
# ErrorMessage = Return Text with problem (seperated by Tabstopp) if nothing, then no error message
# Readout = Real Readout without corrections (NewValue)
ErrorReturn=OldValue, ErrorMessage, Readout
#ErrorReturn=OldValue, ErrorMessage
#ErrorReturn=NewValue, ErrorMessage


[alignment]
initial_rotation_angle=180

Expand Down
100 changes: 80 additions & 20 deletions code/lib/ZaehlerstandClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ def __init__(self):
print('Digital Model Init Done')
self.LoadFileFromHTTP = lib.LoadFileFromHTTPClass.LoadFileFromHttp()

self.ConsistencyEnabled = False
if config.has_option('ConsistencyCheck', 'Enabled'):
self.ConsistencyEnabled = config['ConsistencyCheck']['Enabled']
if self.ConsistencyEnabled.upper() == 'TRUE':
self.ConsistencyEnabled = True

self.AllowNegativeRates = True
if config.has_option('ConsistencyCheck', 'AllowNegativeRates'):
self.AllowNegativeRates = config['ConsistencyCheck']['AllowNegativeRates']
if self.AllowNegativeRates.upper() == 'FALSE':
self.AllowNegativeRates = False

if config.has_option('ConsistencyCheck', 'MaxRateValue'):
self.MaxRateValue = float(config['ConsistencyCheck']['MaxRateValue'])
if config.has_option('ConsistencyCheck', 'ErrorReturn'):
self.ErrorReturn = config['ConsistencyCheck']['ErrorReturn']

self.LastVorkomma = ''
self.LastNachkomma = ''

Expand Down Expand Up @@ -55,36 +72,23 @@ def getROI(self, url):
return txt


def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = False):
def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = False, ignoreConsistencyCheck = False):
txt, logtime = self.LoadFileFromHTTP.LoadImageFromURL(url, './image_tmp/original.jpg')

if len(txt) == 0:
print('Start CutImage')
print('Start CutImage, AnalogReadout, DigitalReadout')
resultcut = self.CutImage.Cut('./image_tmp/original.jpg')

print('Start AnalogNeedle Readout')
resultanalog = self.readAnalogNeedle.Readout(resultcut[0], logtime)

print('Start DigitalDigit Readout')
resultdigital = self.readDigitalDigit.Readout(resultcut[1], logtime)

nachkomma = self.AnalogReadoutToValue(resultanalog)
vorkomma = self.DigitalReadoutToValue(resultdigital, UsePreValue, self.LastNachkomma, nachkomma)

self.LastNachkomma = nachkomma
if not('N' in vorkomma):
self.LastVorkomma = vorkomma

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

zaehlerstand = str(vorkomma.lstrip("0")) + '.' + str(nachkomma)

print('Start Making Zaehlerstand')

if single:
txt = zaehlerstand
else:
txt = zaehlerstand + '\t' + vorkomma + '\t' + nachkomma
(error, errortxt) = self.checkConsistency(ignoreConsistencyCheck)
self.UpdateLastValues(error)
txt = self.MakeReturnValue(error, errortxt, single)

if not simple:
txt = txt + '<p>Aligned Image: <p><img src=/image_tmp/alg.jpg></img><p>'
Expand All @@ -103,6 +107,62 @@ def getZaehlerstand(self, url, simple = True, UsePreValue = False, single = Fals
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)
if not single:
output = output + '\t' + self.akt_vorkomma + '\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)
if not single:
output = output + '\t' + self.akt_vorkomma + '\t' + self.akt_nachkomma
return output

def UpdateLastValues(self, error):
if 'N' in self.akt_vorkomma:
return
if error:
if self.ErrorReturn.find('NewValue') > -1:
self.LastNachkomma = self.akt_nachkomma
self.LastVorkomma = self.akt_vorkomma
else:
self.akt_nachkomma = self.LastNachkomma
self.akt_vorkomma = self.LastVorkomma
else:
self.LastNachkomma = self.akt_nachkomma
self.LastVorkomma = self.akt_vorkomma

def checkConsistency(self, ignoreConsistencyCheck):
error = False
errortxt = ''
if (len(self.LastVorkomma) > 0) and not('N' in self.akt_vorkomma) and self.ConsistencyEnabled:
akt_zaehlerstand = float(str(self.akt_vorkomma.lstrip("0")) + '.' + str(self.akt_nachkomma))
old_zaehlerstand = float(str(self.LastVorkomma.lstrip("0")) + '.' + str(self.LastNachkomma))
delta = akt_zaehlerstand - old_zaehlerstand
if not(self.AllowNegativeRates) and (delta < 0):
error = True
errortxt = "ErrorNegativeRate"
if abs(delta) > self.MaxRateValue:
if error:
errortxt = "ErrorRateTooHigh (" + str(delta) + ")" + errortxt
else:
errortxt = "ErrorRateTooHigh (" + str(delta) + ")"
error = True
if self.ErrorReturn.find('ErrorMessage') == -1:
errortxt = ''
if error and (self.ErrorReturn.find('Readout') > -1):
if len(errortxt):
errortxt = errortxt + '\t' + str(akt_zaehlerstand)
else:
errortxt = str(akt_zaehlerstand)
return (error, errortxt)

def AnalogReadoutToValue(self, res_analog):
prev = -1
erg = ''
Expand Down
Binary file added code/lib/__pycache__/CutImageClass.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added code/lib/__pycache__/__init__.cpython-37.pyc
Binary file not shown.

0 comments on commit df79d7e

Please sign in to comment.