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
a3693bd7
Commit
a3693bd7
authored
Jun 14, 2024
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set shape to 0.0 if in current processing run no contour
was detected.
parent
24a55c54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
oi-sensor/oi-sensor.py
oi-sensor/oi-sensor.py
+14
-2
No files found.
oi-sensor/oi-sensor.py
View file @
a3693bd7
...
...
@@ -131,6 +131,7 @@ async def main():
now
=
time
.
time
()
*
1000
diff
=
(
now
-
before
)
print
(
"Processing time = %.2f ms, countours = %d"
%
(
diff
,
len
(
contours
)))
contour_detected
=
False
for
cnt
in
contours
:
area
=
cv2
.
contourArea
(
cnt
)
approx
=
cv2
.
approxPolyDP
(
cnt
,
0.02
*
cv2
.
arcLength
(
cnt
,
True
),
True
)
...
...
@@ -138,6 +139,7 @@ async def main():
y
=
approx
.
ravel
()[
1
]
number_of_points
=
len
(
approx
)
if
area
>
designated_area_min
and
area
<
designated_area_max
:
contour_detected
=
True
if
not
headless
:
cv2
.
drawContours
(
frame
,
[
approx
],
0
,
(
0
,
0
,
0
),
5
)
if
number_of_points
==
3
:
...
...
@@ -152,8 +154,7 @@ async def main():
if
not
headless
:
cv2
.
putText
(
frame
,
"Circle (%s)"
%
number_of_points
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
result
=
3.0
else
:
result
=
0.0
# printout
print
(
"
\
t
Detected area (px)=%.2f, result=%d"
%
(
area
,
result
))
...
...
@@ -173,6 +174,17 @@ async def main():
current_shape
=
result
await
myvar
.
write_value
(
result
)
# break current countour detection loop as in this example we care
# for first detected SHAPE, we do not expect more shapes
break
if
not
contour_detected
:
# no countours actually detected thus update OPC UA server's node attribute
result
=
0.0
result_stack
.
append
(
result
)
current_shape
=
result
await
myvar
.
write_value
(
result
)
# show current MASK and camera output windows
if
not
headless
:
cv2
.
imshow
(
"Frame"
,
frame
)
...
...
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