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
150c2935
Commit
150c2935
authored
Feb 20, 2020
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16610 from AbsorbedInThought:patch-1
parents
30331eef
8177adbd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
grabcut.py
samples/python/grabcut.py
+6
-8
No files found.
samples/python/grabcut.py
View file @
150c2935
...
...
@@ -11,10 +11,10 @@ USAGE:
README FIRST:
Two windows will show up, one for input and one for output.
At first, in input window, draw a rectangle around the object using
mouse right
button. Then press 'n' to segment the object (once or a few times)
At first, in input window, draw a rectangle around the object using
the
right mouse
button. Then press 'n' to segment the object (once or a few times)
For any finer touch-ups, you can press any of the keys below and draw lines on
the areas you want. Then again press 'n'
for updating
the output.
the areas you want. Then again press 'n'
to update
the output.
Key '0' - To select areas of sure background
Key '1' - To select areas of sure foreground
...
...
@@ -44,8 +44,8 @@ class App():
DRAW_BG
=
{
'color'
:
BLACK
,
'val'
:
0
}
DRAW_FG
=
{
'color'
:
WHITE
,
'val'
:
1
}
DRAW_PR_FG
=
{
'color'
:
GREEN
,
'val'
:
3
}
DRAW_PR_BG
=
{
'color'
:
RED
,
'val'
:
2
}
DRAW_PR_FG
=
{
'color'
:
GREEN
,
'val'
:
3
}
# setting up flags
rect
=
(
0
,
0
,
1
,
1
)
...
...
@@ -160,14 +160,12 @@ class App():
print
(
""" For finer touchups, mark foreground and background after pressing keys 0-3
and again press 'n'
\n
"""
)
try
:
if
(
self
.
rect_or_mask
==
0
):
# grabcut with rect
bgdmodel
=
np
.
zeros
((
1
,
65
),
np
.
float64
)
fgdmodel
=
np
.
zeros
((
1
,
65
),
np
.
float64
)
if
(
self
.
rect_or_mask
==
0
):
# grabcut with rect
cv
.
grabCut
(
self
.
img2
,
self
.
mask
,
self
.
rect
,
bgdmodel
,
fgdmodel
,
1
,
cv
.
GC_INIT_WITH_RECT
)
self
.
rect_or_mask
=
1
elif
self
.
rect_or_mask
==
1
:
# grabcut with mask
bgdmodel
=
np
.
zeros
((
1
,
65
),
np
.
float64
)
fgdmodel
=
np
.
zeros
((
1
,
65
),
np
.
float64
)
elif
(
self
.
rect_or_mask
==
1
):
# grabcut with mask
cv
.
grabCut
(
self
.
img2
,
self
.
mask
,
self
.
rect
,
bgdmodel
,
fgdmodel
,
1
,
cv
.
GC_INIT_WITH_MASK
)
except
:
import
traceback
...
...
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