Commit 69a175a4 authored by Ivan Tyagov's avatar Ivan Tyagov

Do not draw in headless mode. Optimize.

parent dd9aea80
......@@ -129,21 +129,28 @@ async def main():
approx = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt, True), True)
x = approx.ravel()[0]
y = approx.ravel()[1]
number_of_points = len(approx)
if area > designated_area_min and area < designated_area_max:
print("\tDetected area (px)=%.2f" %area)
cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5)
number_of_points = len(approx)
if not headless:
cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5)
if number_of_points == 3:
cv2.putText(frame, "Triangle", (x, y), font, 1, (0, 0, 0))
await myvar.write_value(1.0)
if not headless:
cv2.putText(frame, "Triangle", (x, y), font, 1, (0, 0, 0))
result = 1.0
elif number_of_points == 4:
cv2.putText(frame, "Rectangle", (x, y), font, 1, (0, 0, 0))
await myvar.write_value(2.0)
if not headless:
cv2.putText(frame, "Rectangle", (x, y), font, 1, (0, 0, 0))
result = 2.0
elif 7 < number_of_points < 20:
cv2.putText(frame, "Circle (%s)" %number_of_points, (x, y), font, 1, (0, 0, 0))
await myvar.write_value(3.0)
if not headless:
cv2.putText(frame, "Circle (%s)" %number_of_points, (x, y), font, 1, (0, 0, 0))
result = 3.0
else:
await myvar.write_value(0.0)
result = 0.0
# printout
print("\tDetected area (px)=%.2f, result=%d" %(area, result))
# update OPC UA server's node attribute
await myvar.write_value(0.0)
# show current MASK and camera output windows
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