Commit d09c5642 authored by Ivan Tyagov's avatar Ivan Tyagov

Add a trackbar which allows user to define the number of pixels

which make up an area of interest for evaluation for us.
parent 12bb1632
...@@ -27,6 +27,7 @@ DEFAULT_LV = (0, 255,) ...@@ -27,6 +27,7 @@ DEFAULT_LV = (0, 255,)
DEFAULT_UH = (135, 180,) DEFAULT_UH = (135, 180,)
DEFAULT_US = (190, 255,) DEFAULT_US = (190, 255,)
DEFAULT_UV = (190, 255,) DEFAULT_UV = (190, 255,)
DEFAULT_AREA = (400, 1000,)
# command line handling # command line handling
parser = argparse.ArgumentParser(description='Run optical inspection OPC UA server.') parser = argparse.ArgumentParser(description='Run optical inspection OPC UA server.')
...@@ -73,6 +74,7 @@ async def main(): ...@@ -73,6 +74,7 @@ async def main():
cv2.createTrackbar("U-H", "Trackbars", DEFAULT_UH[0], DEFAULT_UH[1], nothing) cv2.createTrackbar("U-H", "Trackbars", DEFAULT_UH[0], DEFAULT_UH[1], nothing)
cv2.createTrackbar("U-S", "Trackbars", DEFAULT_US[0], DEFAULT_US[1], nothing) cv2.createTrackbar("U-S", "Trackbars", DEFAULT_US[0], DEFAULT_US[1], nothing)
cv2.createTrackbar("U-V", "Trackbars", DEFAULT_UV[0], DEFAULT_UV[1], nothing) cv2.createTrackbar("U-V", "Trackbars", DEFAULT_UV[0], DEFAULT_UV[1], nothing)
cv2.createTrackbar("Area", "Trackbars", DEFAULT_AREA[0], DEFAULT_AREA[1], nothing)
_logger.info("Starting server!") _logger.info("Starting server!")
async with server: async with server:
...@@ -92,6 +94,7 @@ async def main(): ...@@ -92,6 +94,7 @@ async def main():
u_h = cv2.getTrackbarPos("U-H", "Trackbars") u_h = cv2.getTrackbarPos("U-H", "Trackbars")
u_s = cv2.getTrackbarPos("U-S", "Trackbars") u_s = cv2.getTrackbarPos("U-S", "Trackbars")
u_v = cv2.getTrackbarPos("U-V", "Trackbars") u_v = cv2.getTrackbarPos("U-V", "Trackbars")
designated_area = cv2.getTrackbarPos("Area", "Trackbars")
else: else:
# read defaults provided # read defaults provided
l_h = DEFAULT_LH[0] l_h = DEFAULT_LH[0]
...@@ -100,6 +103,7 @@ async def main(): ...@@ -100,6 +103,7 @@ async def main():
u_h = DEFAULT_UH[0] u_h = DEFAULT_UH[0]
u_s = DEFAULT_US[0] u_s = DEFAULT_US[0]
u_v = DEFAULT_UV[0] u_v = DEFAULT_UV[0]
designated_area = DEFAULT_AREA[0]
lower_red = np.array([l_h, l_s, l_v]) lower_red = np.array([l_h, l_s, l_v])
upper_red = np.array([u_h, u_s, u_v]) upper_red = np.array([u_h, u_s, u_v])
...@@ -117,7 +121,7 @@ async def main(): ...@@ -117,7 +121,7 @@ async def main():
x = approx.ravel()[0] x = approx.ravel()[0]
y = approx.ravel()[1] y = approx.ravel()[1]
if area > 400: if area > designated_area:
cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5) cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5)
number_of_points = len(approx) number_of_points = len(approx)
if number_of_points == 3: if number_of_points == 3:
......
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