Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SY32_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Victor Demessance
SY32_project
Commits
826cd765
Commit
826cd765
authored
8 months ago
by
MathieuKoz
Browse files
Options
Downloads
Patches
Plain Diff
Create selective_search.py
parent
fb29bdd9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/selective_search.py
+37
-0
37 additions, 0 deletions
utils/selective_search.py
with
37 additions
and
0 deletions
utils/selective_search.py
0 → 100644
+
37
−
0
View file @
826cd765
import
cv2
import
matplotlib.pyplot
as
plt
def
selective_search
(
image
,
visualize
=
True
,
visulize_count
=
100
):
# Convert image to BGR format for OpenCV
image_bgr
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2BGR
)
# Initialiser la recherche sélective
ss
=
cv2
.
ximgproc
.
segmentation
.
createSelectiveSearchSegmentation
()
ss
.
setBaseImage
(
image_bgr
)
# Utiliser la recherche sélective en mode rapide (ou en mode qualité)
ss
.
switchToSelectiveSearchFast
()
# Pour la recherche rapide
# ss.switchToSelectiveSearchQuality() # Pour une recherche plus précise
# Obtenir les régions candidates
roi
=
ss
.
process
()
if
visualize
:
# Dessiner les régions candidates sur l'image
for
(
x
,
y
,
w
,
h
)
in
roi
[:
visulize_count
]:
# Limiter à 100 régions pour la visualisation
cv2
.
rectangle
(
image_bgr
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
0
,
255
,
0
),
2
)
# Convertir l'image BGR en RGB pour Matplotlib
image_rgb
=
cv2
.
cvtColor
(
image_bgr
,
cv2
.
COLOR_BGR2RGB
)
# Afficher l'image avec les régions candidates
plt
.
figure
(
figsize
=
(
10
,
10
))
plt
.
imshow
(
image_rgb
)
plt
.
axis
(
'
off
'
)
# Cacher les axes pour une meilleure visualisation
plt
.
show
()
return
roi
img
=
cv2
.
imread
(
"
./data/val/images/0846.jpg
"
)
img_rgb
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
# Assurer que l'image est en RGB
result
=
selective_search
(
img_rgb
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment