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
2075d848
Commit
2075d848
authored
Jun 14, 2024
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement some optimization in shape detection.
parent
69a175a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
oi-sensor/oi-sensor.py
oi-sensor/oi-sensor.py
+23
-2
No files found.
oi-sensor/oi-sensor.py
View file @
2075d848
...
@@ -19,6 +19,7 @@ from asyncua import Server
...
@@ -19,6 +19,7 @@ from asyncua import Server
import
argparse
import
argparse
import
time
import
time
SLEEP_DURATION
=
10e-3
# 10 milliseconds
SLEEP_DURATION
=
10e-3
# 10 milliseconds
# algorith defaults
# algorith defaults
...
@@ -39,6 +40,8 @@ a('--ipv4', help='The IPv4 address on which the OPC UA server runs', default="0.
...
@@ -39,6 +40,8 @@ a('--ipv4', help='The IPv4 address on which the OPC UA server runs', default="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
)
a
(
'--headless'
,
help
=
'Run without screen in a headless mode (boolean, default=0)'
,
default
=
False
)
# XXX: allow to specify from CLI DEFAULT_LH & friends
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
ipv4
=
args
.
ipv4
ipv4
=
args
.
ipv4
port
=
args
.
port
port
=
args
.
port
...
@@ -65,6 +68,10 @@ async def main():
...
@@ -65,6 +68,10 @@ async def main():
myvar
=
await
myobj
.
add_variable
(
idx
,
"shape"
,
0.0
)
myvar
=
await
myobj
.
add_variable
(
idx
,
"shape"
,
0.0
)
await
myvar
.
set_writable
()
await
myvar
.
set_writable
()
# Initialize
result_stack
=
[]
current_shape
=
0.0
# init camera
# init camera
cap
=
cv2
.
VideoCapture
(
camera
)
cap
=
cv2
.
VideoCapture
(
camera
)
font
=
cv2
.
FONT_HERSHEY_COMPLEX
font
=
cv2
.
FONT_HERSHEY_COMPLEX
...
@@ -149,8 +156,22 @@ async def main():
...
@@ -149,8 +156,22 @@ async def main():
result
=
0.0
result
=
0.0
# printout
# printout
print
(
"
\
t
Detected area (px)=%.2f, result=%d"
%
(
area
,
result
))
print
(
"
\
t
Detected area (px)=%.2f, result=%d"
%
(
area
,
result
))
# update list for last X results (FILO)
default_occurence_number
=
5
result_stack
.
append
(
result
)
if
len
(
result_stack
)
>
default_occurence_number
:
# leave only last X items
result_stack
=
result_stack
[
-
default_occurence_number
:]
# to avoid sometimes errors in detection algorithm we change OPC UA node
# variable only if at least we have 40% (2) of last 5 items detected as this
# shape. Not complex but avoid false results.
count
=
result_stack
.
count
(
result
)
if
count
>=
2
:
# update OPC UA server's node attribute
# update OPC UA server's node attribute
await
myvar
.
write_value
(
0.0
)
current_shape
=
result
await
myvar
.
write_value
(
result
)
# show current MASK and camera output windows
# show current MASK and camera output windows
if
not
headless
:
if
not
headless
:
...
...
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