Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-133
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
2023-133
2023-133
Commits
173a8fca
Commit
173a8fca
authored
Sep 08, 2023
by
Basnayake N.S.N.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
235941bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
finding HSV/test.py
finding HSV/test.py
+61
-0
No files found.
finding HSV/test.py
0 → 100644
View file @
173a8fca
import
cv2
import
numpy
as
np
rois
=
[]
# This will store top-left and bottom-right points of rectangles
current_roi
=
[]
# Temporary storage for current rectangle being drawn
def
draw_roi
(
event
,
x
,
y
,
flags
,
param
):
global
current_roi
,
img_temp
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
current_roi
=
[(
x
,
y
)]
elif
event
==
cv2
.
EVENT_LBUTTONUP
:
current_roi
.
append
((
x
,
y
))
cv2
.
rectangle
(
img_temp
,
current_roi
[
0
],
current_roi
[
1
],
(
0
,
255
,
0
),
2
)
rois
.
append
(
current_roi
)
cv2
.
imshow
(
"Select ROIs"
,
img_temp
)
# Load the image
img
=
cv2
.
imread
(
'test15.jpg'
)
img_temp
=
img
.
copy
()
cv2
.
namedWindow
(
"Select ROIs"
)
cv2
.
setMouseCallback
(
"Select ROIs"
,
draw_roi
)
while
True
:
cv2
.
imshow
(
"Select ROIs"
,
img_temp
)
key
=
cv2
.
waitKey
(
1
)
# If 'c' key is pressed, break out of loop to compute
if
key
==
ord
(
'c'
):
break
# If 'ESC' key is pressed, exit
if
key
==
27
:
cv2
.
destroyAllWindows
()
exit
()
# Now, compute the combined HSV range of all selected ROIs
h_min
,
h_max
=
[],
[]
s_min
,
s_max
=
[],
[]
v_min
,
v_max
=
[],
[]
img_hsv
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2HSV
)
for
roi
in
rois
:
roi_data
=
img_hsv
[
roi
[
0
][
1
]:
roi
[
1
][
1
],
roi
[
0
][
0
]:
roi
[
1
][
0
]]
h
,
s
,
v
=
cv2
.
split
(
roi_data
)
h_min
.
append
(
h
.
min
())
h_max
.
append
(
h
.
max
())
s_min
.
append
(
s
.
min
())
s_max
.
append
(
s
.
max
())
v_min
.
append
(
v
.
min
())
v_max
.
append
(
v
.
max
())
print
(
f
"H range: ({min(h_min)}, {max(h_max)})"
)
print
(
f
"S range: ({min(s_min)}, {max(s_max)})"
)
print
(
f
"V range: ({min(v_min)}, {max(v_max)})"
)
cv2
.
destroyAllWindows
()
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