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 ...@@ -20,16 +20,26 @@ import argparse
SLEEP_DURATION = 10e-3 # 10 milliseconds 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 # command line handling
parser = argparse.ArgumentParser(description='Run optical inspection OPC UA server.') parser = argparse.ArgumentParser(description='Run optical inspection OPC UA server.')
a = parser.add_argument a = parser.add_argument
a('--ipv4', help='The IPv4 address on which the OPC UA server runs', default="0.0.0.0") 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('--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('--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() args = parser.parse_args()
ipv4 = args.ipv4 ipv4 = args.ipv4
port = args.port port = args.port
camera = int(args.camera) camera = int(args.camera)
headless = bool(int(args.headless))
def nothing(x): def nothing(x):
# any operation # any operation
...@@ -53,14 +63,16 @@ async def main(): ...@@ -53,14 +63,16 @@ async def main():
# init camera # init camera
cap = cv2.VideoCapture(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 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!") _logger.info("Starting server!")
async with server: async with server:
...@@ -73,12 +85,22 @@ async def main(): ...@@ -73,12 +85,22 @@ async def main():
# read and process camera # read and process camera
_, frame = cap.read() _, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
l_h = cv2.getTrackbarPos("L-H", "Trackbars") if not headless:
l_s = cv2.getTrackbarPos("L-S", "Trackbars") l_h = cv2.getTrackbarPos("L-H", "Trackbars")
l_v = cv2.getTrackbarPos("L-V", "Trackbars") l_s = cv2.getTrackbarPos("L-S", "Trackbars")
u_h = cv2.getTrackbarPos("U-H", "Trackbars") l_v = cv2.getTrackbarPos("L-V", "Trackbars")
u_s = cv2.getTrackbarPos("U-S", "Trackbars") u_h = cv2.getTrackbarPos("U-H", "Trackbars")
u_v = cv2.getTrackbarPos("U-V", "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]) 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])
...@@ -110,8 +132,10 @@ async def main(): ...@@ -110,8 +132,10 @@ async def main():
else: else:
await myvar.write_value(0.0) await myvar.write_value(0.0)
cv2.imshow("Frame", frame) # show current MASK and camera output windows
cv2.imshow("Mask", mask) if not headless:
cv2.imshow("Frame", frame)
cv2.imshow("Mask", mask)
key = cv2.waitKey(1) key = cv2.waitKey(1)
if key == 27: 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