Commit a8a51c02 authored by Ivan Tyagov's avatar Ivan Tyagov

Better printout.

Update OPC UA node only if new shape is different
than last one.
parent 99145da9
...@@ -70,6 +70,7 @@ async def main(): ...@@ -70,6 +70,7 @@ async def main():
# Initialize # Initialize
result = 0.0 result = 0.0
shape_change_counter = 0
result_stack = [] result_stack = []
current_shape = 0.0 current_shape = 0.0
...@@ -157,23 +158,13 @@ async def main(): ...@@ -157,23 +158,13 @@ async def main():
result = 3.0 result = 3.0
# printout # printout
print("\tDetected area (px)=%.2f, result=%d" %(area, result)) print("\tDetected area (px)=%.2f, result=%d, shape changes=%d" %(area, result, shape_change_counter))
# update list for last X results (FILO) # update list for last X results (FILO)
default_occurence_number = 5
result_stack.append(result) result_stack.append(result)
if len(result_stack) > default_occurence_number: current_shape = result
# leave only last X items shape_change_counter += 1
result_stack = result_stack[-default_occurence_number:] await myvar.write_value(result)
# to avoid sometimes errors in detection algorithm we change OPC UA node
# variable only if at least we have 2 (40%) of last 5 (100%) items detected as this
# shape. Not complex but avoid false results.
count = result_stack.count(result)
if count >= 2:
# update OPC UA server's node attribute
current_shape = result
await myvar.write_value(result)
# break current countour detection loop as in this example we care # break current countour detection loop as in this example we care
# for first detected SHAPE, we do not expect more shapes # for first detected SHAPE, we do not expect more shapes
...@@ -183,8 +174,10 @@ async def main(): ...@@ -183,8 +174,10 @@ async def main():
# no countours actually detected thus update OPC UA server's node attribute # no countours actually detected thus update OPC UA server's node attribute
result = 0.0 result = 0.0
result_stack.append(result) result_stack.append(result)
current_shape = result shape_change_counter += 1
await myvar.write_value(result) await myvar.write_value(result)
current_shape = result
print("\tNo shape detected, result=%d, shape changes=%d" %(result, shape_change_counter))
# show current MASK and camera output windows # show current MASK and camera output windows
if not headless: if not headless:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment