Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
osie
Commits
9af7c90e
Commit
9af7c90e
authored
May 20, 2024
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add another CLI mode which allows to run oi-sensor in environment
where a X11 server is NOT available.
parent
6a8981fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
15 deletions
+39
-15
oi-sensor/oi-sensor.py
oi-sensor/oi-sensor.py
+39
-15
No files found.
oi-sensor/oi-sensor.py
View file @
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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment