Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
724cc5b4
Commit
724cc5b4
authored
Jul 02, 2011
by
Alexander Mordvintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
floodfill.py sample added
parent
1c96aac5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
floodfill.py
samples/python2/floodfill.py
+64
-0
No files found.
samples/python2/floodfill.py
0 → 100644
View file @
724cc5b4
import
numpy
as
np
import
cv2
,
cv
help_message
=
'''USAGE: floodfill.py [<image>]
Click on the image to set seed point
Keys:
f - toggle floating range
c - toggle 4/8 connectivity
ESC - exit
'''
if
__name__
==
'__main__'
:
import
sys
try
:
fn
=
sys
.
argv
[
1
]
except
:
fn
=
'../cpp/fruits.jpg'
print
help_message
img
=
cv2
.
imread
(
fn
,
True
)
h
,
w
=
img
.
shape
[:
2
]
mask
=
np
.
zeros
((
h
+
2
,
w
+
2
),
np
.
uint8
)
seed_pt
=
None
fixed_range
=
True
connectivity
=
4
def
update
(
dummy
=
None
):
if
seed_pt
is
None
:
cv2
.
imshow
(
'floodfill'
,
img
)
return
flooded
=
img
.
copy
()
mask
[:]
=
0
lo
=
cv2
.
getTrackbarPos
(
'lo'
,
'floodfill'
)
hi
=
cv2
.
getTrackbarPos
(
'hi'
,
'floodfill'
)
flags
=
connectivity
if
fixed_range
:
flags
|=
cv2
.
FLOODFILL_FIXED_RANGE
cv2
.
floodFill
(
flooded
,
mask
,
seed_pt
,
(
255
,
255
,
255
),
(
lo
,)
*
3
,
(
hi
,)
*
3
,
flags
)
cv2
.
circle
(
flooded
,
seed_pt
,
2
,
(
0
,
0
,
255
),
-
1
)
cv2
.
imshow
(
'floodfill'
,
flooded
)
def
onmouse
(
event
,
x
,
y
,
flags
,
param
):
global
seed_pt
if
flags
&
cv
.
CV_EVENT_FLAG_LBUTTON
:
seed_pt
=
x
,
y
update
()
update
()
cv2
.
setMouseCallback
(
'floodfill'
,
onmouse
)
cv2
.
createTrackbar
(
'lo'
,
'floodfill'
,
20
,
255
,
update
)
cv2
.
createTrackbar
(
'hi'
,
'floodfill'
,
20
,
255
,
update
)
while
True
:
ch
=
cv2
.
waitKey
()
if
ch
==
27
:
break
if
ch
==
ord
(
'f'
):
fixed_range
=
not
fixed_range
print
'using
%
s range'
%
(
'floating'
,
'fixed'
)[
fixed_range
]
update
()
if
ch
==
ord
(
'c'
):
connectivity
=
12
-
connectivity
print
'connectivity ='
,
connectivity
update
()
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