Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
maskrcnn
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
人工智能
maskrcnn
Commits
af132c51
Commit
af132c51
authored
Jan 21, 2019
by
Aaron Lelevier
Committed by
Francisco Massa
Jan 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add helper function 'cv2_utils.findContours' to maintain version compatibility (#354)
fixes #339
parent
205fa4e7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
predictor.py
demo/predictor.py
+2
-1
cv2_util.py
maskrcnn_benchmark/utils/cv2_util.py
+24
-0
instances2dict_with_polygons.py
tools/cityscapes/instances2dict_with_polygons.py
+3
-1
No files found.
demo/predictor.py
View file @
af132c51
...
...
@@ -8,6 +8,7 @@ from maskrcnn_benchmark.utils.checkpoint import DetectronCheckpointer
from
maskrcnn_benchmark.structures.image_list
import
to_image_list
from
maskrcnn_benchmark.modeling.roi_heads.mask_head.inference
import
Masker
from
maskrcnn_benchmark
import
layers
as
L
from
maskrcnn_benchmark.utils
import
cv2_util
class
COCODemo
(
object
):
...
...
@@ -287,7 +288,7 @@ class COCODemo(object):
for
mask
,
color
in
zip
(
masks
,
colors
):
thresh
=
mask
[
0
,
:,
:,
None
]
_
,
contours
,
hierarchy
=
cv2
.
findContours
(
contours
,
hierarchy
=
cv2_util
.
findContours
(
thresh
,
cv2
.
RETR_TREE
,
cv2
.
CHAIN_APPROX_SIMPLE
)
image
=
cv2
.
drawContours
(
image
,
contours
,
-
1
,
color
,
3
)
...
...
maskrcnn_benchmark/utils/cv2_util.py
0 → 100644
View file @
af132c51
"""
Module for cv2 utility functions and maintaining version compatibility
between 3.x and 4.x
"""
import
cv2
def
findContours
(
*
args
,
**
kwargs
):
"""
Wraps cv2.findContours to maintain compatiblity between versions
3 and 4
Returns:
contours, hierarchy
"""
if
cv2
.
__version__
.
startswith
(
'4'
):
contours
,
hierarchy
=
cv2
.
findContours
(
*
args
,
**
kwargs
)
elif
cv2
.
__version__
.
startswith
(
'3'
):
_
,
contours
,
hierarchy
=
cv2
.
findContours
(
*
args
,
**
kwargs
)
else
:
raise
AssertionError
(
'cv2 must be either version 3 or 4 to call this method'
)
return
contours
,
hierarchy
tools/cityscapes/instances2dict_with_polygons.py
View file @
af132c51
...
...
@@ -13,6 +13,8 @@ from csHelpers import *
from
cityscapesscripts.evaluation.instance
import
*
from
cityscapesscripts.helpers.csHelpers
import
*
import
cv2
from
maskrcnn_benchmark.utils
import
cv2_util
def
instances2dict_with_polygons
(
imageFileList
,
verbose
=
False
):
imgCount
=
0
...
...
@@ -46,7 +48,7 @@ def instances2dict_with_polygons(imageFileList, verbose=False):
#instances[id2label[instanceObj.labelID].name].append(instanceObj.toDict())
if
id2label
[
instanceObj
.
labelID
]
.
hasInstances
:
mask
=
(
imgNp
==
instanceId
)
.
astype
(
np
.
uint8
)
im2
,
contour
,
hier
=
cv2
.
findContours
(
contour
,
hier
=
cv2_util
.
findContours
(
mask
.
copy
(),
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_NONE
)
polygons
=
[
c
.
reshape
(
-
1
)
.
tolist
()
for
c
in
contour
]
...
...
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