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
7d08c150
Commit
7d08c150
authored
May 22, 2024
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to sort on minimal and maximal contour pixel size.
More debugging information.
parent
cce5355f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
oi-sensor/oi-sensor.py
oi-sensor/oi-sensor.py
+17
-8
No files found.
oi-sensor/oi-sensor.py
View file @
7d08c150
...
...
@@ -17,6 +17,7 @@ import asyncio
import
logging
from
asyncua
import
Server
import
argparse
import
time
SLEEP_DURATION
=
10e-3
# 10 milliseconds
...
...
@@ -24,10 +25,12 @@ SLEEP_DURATION = 10e-3 # 10 milliseconds
DEFAULT_LH
=
(
0
,
180
,)
DEFAULT_LS
=
(
0
,
255
,)
DEFAULT_LV
=
(
0
,
255
,)
DEFAULT_UH
=
(
1
35
,
180
,)
DEFAULT_UH
=
(
1
80
,
180
,)
DEFAULT_US
=
(
190
,
255
,)
DEFAULT_UV
=
(
190
,
255
,)
DEFAULT_AREA
=
(
400
,
1000
,)
# the minimal number of pixes which we consider as a shape
# and the maximal (configurable) such
DEFAULT_AREA
=
(
10000
,
50000
,)
# command line handling
parser
=
argparse
.
ArgumentParser
(
description
=
'Run optical inspection OPC UA server.'
)
...
...
@@ -74,7 +77,8 @@ async def main():
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
)
cv2
.
createTrackbar
(
"Area"
,
"Trackbars"
,
DEFAULT_AREA
[
0
],
DEFAULT_AREA
[
1
],
nothing
)
cv2
.
createTrackbar
(
"Area (min)"
,
"Trackbars"
,
DEFAULT_AREA
[
0
],
DEFAULT_AREA
[
1
],
nothing
)
cv2
.
createTrackbar
(
"Area (max)"
,
"Trackbars"
,
DEFAULT_AREA
[
1
],
DEFAULT_AREA
[
1
],
nothing
)
_logger
.
info
(
"Starting server!"
)
async
with
server
:
...
...
@@ -84,6 +88,7 @@ async def main():
# recognition. Thus give (roughly) some CPU time so both can work together.
await
asyncio
.
sleep
(
SLEEP_DURATION
)
before
=
time
.
time
()
*
1000
# read and process camera
_
,
frame
=
cap
.
read
()
hsv
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2HSV
)
...
...
@@ -94,7 +99,8 @@ async def main():
u_h
=
cv2
.
getTrackbarPos
(
"U-H"
,
"Trackbars"
)
u_s
=
cv2
.
getTrackbarPos
(
"U-S"
,
"Trackbars"
)
u_v
=
cv2
.
getTrackbarPos
(
"U-V"
,
"Trackbars"
)
designated_area
=
cv2
.
getTrackbarPos
(
"Area"
,
"Trackbars"
)
designated_area_min
=
cv2
.
getTrackbarPos
(
"Area (min)"
,
"Trackbars"
)
designated_area_max
=
cv2
.
getTrackbarPos
(
"Area (max)"
,
"Trackbars"
)
else
:
# read defaults provided
l_h
=
DEFAULT_LH
[
0
]
...
...
@@ -103,7 +109,8 @@ async def main():
u_h
=
DEFAULT_UH
[
0
]
u_s
=
DEFAULT_US
[
0
]
u_v
=
DEFAULT_UV
[
0
]
designated_area
=
DEFAULT_AREA
[
0
]
designated_area_min
=
DEFAULT_AREA
[
0
]
designated_area_max
=
DEFAULT_AREA
[
1
]
lower_red
=
np
.
array
([
l_h
,
l_s
,
l_v
])
upper_red
=
np
.
array
([
u_h
,
u_s
,
u_v
])
...
...
@@ -114,14 +121,16 @@ async def main():
# Contours detection
contours
,
_
=
cv2
.
findContours
(
mask
,
cv2
.
RETR_TREE
,
cv2
.
CHAIN_APPROX_SIMPLE
)
now
=
time
.
time
()
*
1000
diff
=
(
now
-
before
)
print
(
"Processing time = %.2f ms, countours = %d"
%
(
diff
,
len
(
contours
)))
for
cnt
in
contours
:
area
=
cv2
.
contourArea
(
cnt
)
approx
=
cv2
.
approxPolyDP
(
cnt
,
0.02
*
cv2
.
arcLength
(
cnt
,
True
),
True
)
x
=
approx
.
ravel
()[
0
]
y
=
approx
.
ravel
()[
1
]
if
area
>
designated_area
:
if
area
>
designated_area_min
and
area
<
designated_area_max
:
print
(
"
\
t
Detected area (px)=%.2f"
%
area
)
cv2
.
drawContours
(
frame
,
[
approx
],
0
,
(
0
,
0
,
0
),
5
)
number_of_points
=
len
(
approx
)
if
number_of_points
==
3
:
...
...
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