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
1
Merge Requests
1
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
5f45f7e3
Commit
5f45f7e3
authored
May 16, 2024
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Plain Diff
Oi sensor
See merge request
!49
parents
5e739a2e
f24d4b8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
oi-sensor/oi-sensor.py
oi-sensor/oi-sensor.py
+28
-15
No files found.
oi-sensor/oi-sensor.py
View file @
5f45f7e3
...
...
@@ -16,6 +16,20 @@ import numpy as np
import
asyncio
import
logging
from
asyncua
import
Server
import
argparse
SLEEP_DURATION
=
10e-3
# 10 milliseconds
# 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
)
args
=
parser
.
parse_args
()
ipv4
=
args
.
ipv4
port
=
args
.
port
camera
=
int
(
args
.
camera
)
def
nothing
(
x
):
# any operation
...
...
@@ -26,7 +40,7 @@ async def main():
# setup our server
server
=
Server
()
await
server
.
init
()
server
.
set_endpoint
(
"opc.tcp://
0.0.0.0:4840/freeopcua/server/"
)
server
.
set_endpoint
(
"opc.tcp://
%s:%s/freeopcua/server/"
%
(
ipv4
,
port
)
)
# set up our own namespace, not really necessary but should as spec
uri
=
"http://examples.freeopcua.github.io"
...
...
@@ -38,22 +52,23 @@ async def main():
await
myvar
.
set_writable
()
# init camera
cap
=
cv2
.
VideoCapture
(
0
)
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"
,
3
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-H"
,
"Trackbars"
,
39
,
180
,
nothing
)
cv2
.
createTrackbar
(
"U-S"
,
"Trackbars"
,
1
55
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-V"
,
"Trackbars"
,
1
48
,
255
,
nothing
)
cv2
.
createTrackbar
(
"L-V"
,
"Trackbars"
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-H"
,
"Trackbars"
,
135
,
180
,
nothing
)
cv2
.
createTrackbar
(
"U-S"
,
"Trackbars"
,
1
90
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-V"
,
"Trackbars"
,
1
90
,
255
,
nothing
)
font
=
cv2
.
FONT_HERSHEY_COMPLEX
_logger
.
info
(
"Starting server!"
)
async
with
server
:
while
True
:
# XXX: find out why we need to sleep (otherwise OPC UA server stops work)
await
asyncio
.
sleep
(
0.0001
)
# script runs concurrently OPC UA server and openCV optical shape
# recognition. Thus give (roughly) some CPU time so both can work together.
await
asyncio
.
sleep
(
SLEEP_DURATION
)
# read and process camera
_
,
frame
=
cap
.
read
()
...
...
@@ -82,18 +97,16 @@ async def main():
if
area
>
400
:
cv2
.
drawContours
(
frame
,
[
approx
],
0
,
(
0
,
0
,
0
),
5
)
if
len
(
approx
)
==
3
:
number_of_points
=
len
(
approx
)
if
number_of_points
==
3
:
cv2
.
putText
(
frame
,
"Triangle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
await
myvar
.
write_value
(
1.0
)
#_logger.info("Triangle")
elif
len
(
approx
)
==
4
:
elif
number_of_points
==
4
:
cv2
.
putText
(
frame
,
"Rectangle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
await
myvar
.
write_value
(
2.0
)
#_logger.info("Rectangle")
elif
7
<
len
(
approx
)
<
20
:
cv2
.
putText
(
frame
,
"Circle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
elif
7
<
number_of_points
<
20
:
cv2
.
putText
(
frame
,
"Circle (%s)"
%
number_of_points
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
await
myvar
.
write_value
(
3.0
)
#_logger.info("Circle")
else
:
await
myvar
.
write_value
(
0.0
)
...
...
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