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

Do not draw in headless mode. Optimize.

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