Commit 879f779d authored by Ivan Tyagov's avatar Ivan Tyagov

Oi sensor

See merge request !50
parents 6a8981fd 9af7c90e
......@@ -20,16 +20,26 @@ import argparse
SLEEP_DURATION = 10e-3 # 10 milliseconds
# algorith defaults
DEFAULT_LH = (0, 180,)
DEFAULT_LS = (0, 255,)
DEFAULT_LV = (0, 255,)
DEFAULT_UH = (135, 180,)
DEFAULT_US = (190, 255,)
DEFAULT_UV = (190, 255,)
# command line handling
parser = argparse.ArgumentParser(description='Run optical inspection OPC UA server.')
a = parser.add_argument
a('--ipv4', help='The IPv4 address on which the OPC UA server runs', default="0.0.0.0")
a('--port', help='The port on which the OPC UA server runs', default="4840")
a('--camera', help='The index of the camera (i.e. indxed in /dev/videoX)', default=0)
a('--headless', help='Run without screen in a headless mode (boolean, default=0)', default=False)
args = parser.parse_args()
ipv4 = args.ipv4
port = args.port
camera = int(args.camera)
headless = bool(int(args.headless))
def nothing(x):
# any operation
......@@ -53,14 +63,16 @@ async def main():
# init camera
cap = cv2.VideoCapture(camera)
cv2.namedWindow("Trackbars")
cv2.createTrackbar("L-H", "Trackbars", 0, 180, nothing)
cv2.createTrackbar("L-S", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("L-V", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("U-H", "Trackbars", 135, 180, nothing)
cv2.createTrackbar("U-S", "Trackbars", 190, 255, nothing)
cv2.createTrackbar("U-V", "Trackbars", 190, 255, nothing)
font = cv2.FONT_HERSHEY_COMPLEX
if not headless:
# create UI
cv2.namedWindow("Trackbars")
cv2.createTrackbar("L-H", "Trackbars", DEFAULT_LH[0], DEFAULT_LH[1], nothing)
cv2.createTrackbar("L-S", "Trackbars", DEFAULT_LS[0], DEFAULT_LS[1], nothing)
cv2.createTrackbar("L-V", "Trackbars", DEFAULT_LV[0], DEFAULT_LV[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-V", "Trackbars", DEFAULT_UV[0], DEFAULT_UV[1], nothing)
_logger.info("Starting server!")
async with server:
......@@ -73,12 +85,22 @@ async def main():
# read and process camera
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
l_h = cv2.getTrackbarPos("L-H", "Trackbars")
l_s = cv2.getTrackbarPos("L-S", "Trackbars")
l_v = cv2.getTrackbarPos("L-V", "Trackbars")
u_h = cv2.getTrackbarPos("U-H", "Trackbars")
u_s = cv2.getTrackbarPos("U-S", "Trackbars")
u_v = cv2.getTrackbarPos("U-V", "Trackbars")
if not headless:
l_h = cv2.getTrackbarPos("L-H", "Trackbars")
l_s = cv2.getTrackbarPos("L-S", "Trackbars")
l_v = cv2.getTrackbarPos("L-V", "Trackbars")
u_h = cv2.getTrackbarPos("U-H", "Trackbars")
u_s = cv2.getTrackbarPos("U-S", "Trackbars")
u_v = cv2.getTrackbarPos("U-V", "Trackbars")
else:
# read defaults provided
l_h = DEFAULT_LH[0]
l_s = DEFAULT_LS[0]
l_v = DEFAULT_LV[0]
u_h = DEFAULT_UH[0]
u_s = DEFAULT_US[0]
u_v = DEFAULT_UV[0]
lower_red = np.array([l_h, l_s, l_v])
upper_red = np.array([u_h, u_s, u_v])
......@@ -110,8 +132,10 @@ async def main():
else:
await myvar.write_value(0.0)
cv2.imshow("Frame", frame)
cv2.imshow("Mask", mask)
# show current MASK and camera output windows
if not headless:
cv2.imshow("Frame", frame)
cv2.imshow("Mask", mask)
key = cv2.waitKey(1)
if key == 27:
......
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