Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
larm-astro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Inès EL HADRI
larm-astro
Commits
562e5d33
Commit
562e5d33
authored
Jan 10, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tune HSV in mask_tuner
parent
164186b3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
mask_tuner.py
tuto_vision/mask_tuner.py
+64
-0
No files found.
tuto_vision/mask_tuner.py
0 → 100644
View file @
562e5d33
import
cv2
import
numpy
as
np
def
souris
(
event
,
x
,
y
,
flags
,
param
):
global
lo
,
hi
,
color
,
hsv_px
if
event
==
cv2
.
EVENT_MOUSEMOVE
:
# Conversion des trois couleurs RGB sous la souris en HSV
px
=
frame
[
y
,
x
]
px_array
=
np
.
uint8
([[
px
]])
hsv_px
=
cv2
.
cvtColor
(
px_array
,
cv2
.
COLOR_BGR2HSV
)
if
event
==
cv2
.
EVENT_MBUTTONDBLCLK
:
color
=
image
[
y
,
x
][
0
]
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
if
color
>
5
:
color
-=
1
if
event
==
cv2
.
EVENT_RBUTTONDOWN
:
if
color
<
250
:
color
+=
1
# lo[1]=color-10
# hi[1]=color+10
color
=
100
lo
=
np
.
array
([
58
-
20
,
50
,
20
])
hi
=
np
.
array
([
58
+
20
,
255
,
255
])
color_info
=
(
0
,
0
,
255
)
cap
=
cv2
.
VideoCapture
(
0
)
cv2
.
namedWindow
(
'Camera'
)
cv2
.
setMouseCallback
(
'Camera'
,
souris
)
hsv_px
=
[
0
,
0
,
0
]
# Creating morphological kernel
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
while
True
:
ret
,
frame
=
cap
.
read
()
image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2HSV
)
mask
=
cv2
.
inRange
(
image
,
lo
,
hi
)
mask
=
cv2
.
erode
(
mask
,
kernel
,
iterations
=
1
)
mask
=
cv2
.
dilate
(
mask
,
kernel
,
iterations
=
1
)
image2
=
cv2
.
bitwise_and
(
frame
,
frame
,
mask
=
mask
)
cv2
.
putText
(
frame
,
"Couleur: {:d}"
.
format
(
color
),
(
10
,
30
),
cv2
.
FONT_HERSHEY_DUPLEX
,
1
,
color_info
,
1
,
cv2
.
LINE_AA
)
# Affichage des composantes HSV sous la souris sur l'image
pixel_hsv
=
" "
.
join
(
str
(
values
)
for
values
in
hsv_px
)
font
=
cv2
.
FONT_HERSHEY_SIMPLEX
cv2
.
putText
(
frame
,
"px HSV: "
+
pixel_hsv
,
(
10
,
260
),
font
,
1
,
(
255
,
255
,
255
),
1
,
cv2
.
LINE_AA
)
cv2
.
imshow
(
'Camera'
,
frame
)
cv2
.
imshow
(
'image2'
,
image2
)
cv2
.
imshow
(
'Mask'
,
mask
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
cap
.
release
()
cv2
.
destroyAllWindows
()
\ No newline at end of file
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