Commit a3693bd7 authored by Ivan Tyagov's avatar Ivan Tyagov

Set shape to 0.0 if in current processing run no contour

was detected.
parent 24a55c54
...@@ -131,6 +131,7 @@ async def main(): ...@@ -131,6 +131,7 @@ async def main():
now = time.time() * 1000 now = time.time() * 1000
diff = (now-before) diff = (now-before)
print("Processing time = %.2f ms, countours = %d" %(diff, len(contours))) print("Processing time = %.2f ms, countours = %d" %(diff, len(contours)))
contour_detected = False
for cnt in contours: for cnt in contours:
area = cv2.contourArea(cnt) area = cv2.contourArea(cnt)
approx = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt, True), True) approx = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt, True), True)
...@@ -138,6 +139,7 @@ async def main(): ...@@ -138,6 +139,7 @@ async def main():
y = approx.ravel()[1] y = approx.ravel()[1]
number_of_points = len(approx) number_of_points = len(approx)
if area > designated_area_min and area < designated_area_max: if area > designated_area_min and area < designated_area_max:
contour_detected = True
if not headless: if not headless:
cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5) cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5)
if number_of_points == 3: if number_of_points == 3:
...@@ -152,8 +154,7 @@ async def main(): ...@@ -152,8 +154,7 @@ async def main():
if not headless: if not headless:
cv2.putText(frame, "Circle (%s)" %number_of_points, (x, y), font, 1, (0, 0, 0)) cv2.putText(frame, "Circle (%s)" %number_of_points, (x, y), font, 1, (0, 0, 0))
result = 3.0 result = 3.0
else:
result = 0.0
# printout # printout
print("\tDetected area (px)=%.2f, result=%d" %(area, result)) print("\tDetected area (px)=%.2f, result=%d" %(area, result))
...@@ -173,6 +174,17 @@ async def main(): ...@@ -173,6 +174,17 @@ async def main():
current_shape = result current_shape = result
await myvar.write_value(result) await myvar.write_value(result)
# break current countour detection loop as in this example we care
# for first detected SHAPE, we do not expect more shapes
break
if not contour_detected:
# no countours actually detected thus update OPC UA server's node attribute
result = 0.0
result_stack.append(result)
current_shape = result
await myvar.write_value(result)
# show current MASK and camera output windows # show current MASK and camera output windows
if not headless: if not headless:
cv2.imshow("Frame", frame) cv2.imshow("Frame", frame)
......
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