You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2018/06/07 20:40:44 UTC
[incubator-mxnet] branch master updated: Add frame-resize option to
ssd demo to scale camera input (#11033)
This is an automated email from the ASF dual-hosted git repository.
zhreshold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new afe0e49 Add frame-resize option to ssd demo to scale camera input (#11033)
afe0e49 is described below
commit afe0e4987bbc9c0107ee6c87f64ba45448291285
Author: Pedro Larroy <92...@users.noreply.github.com>
AuthorDate: Thu Jun 7 22:40:25 2018 +0200
Add frame-resize option to ssd demo to scale camera input (#11033)
---
example/ssd/README.md | 3 ++-
example/ssd/dataset/cv2Iterator.py | 15 ++++++++++++---
example/ssd/demo.py | 13 ++++++++++++-
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/example/ssd/README.md b/example/ssd/README.md
index 55387c5..cc03468 100644
--- a/example/ssd/README.md
+++ b/example/ssd/README.md
@@ -17,7 +17,8 @@ remarkable traits of MXNet.
Due to the permission issue, this example is maintained in this [repository](https://github.com/zhreshold/mxnet-ssd) separately. You can use the link regarding specific per example [issues](https://github.com/zhreshold/mxnet-ssd/issues).
### What's new
-* Added live camera capture and detection display (run with --camera flag)
+* Added live camera capture and detection display (run with --camera flag). Example:
+ `./demo.py --camera --cpu --frame-resize 0.5`
* Added multiple trained models.
* Added a much simpler way to compose network from mainstream classification networks (resnet, inception...) and [Guide](symbol/README.md).
* Update to the latest version according to caffe version, with 5% mAP increase.
diff --git a/example/ssd/dataset/cv2Iterator.py b/example/ssd/dataset/cv2Iterator.py
index 469faea..0af8c32 100644
--- a/example/ssd/dataset/cv2Iterator.py
+++ b/example/ssd/dataset/cv2Iterator.py
@@ -26,10 +26,19 @@ class CameraIterator():
"""
def __init__(self, capture=cv2.VideoCapture(0), frame_resize=None):
self._capture = capture
- self._frame_resize = frame_resize
+ self._frame_resize = None
if frame_resize:
- assert isinstance(frame_resize, tuple) and (len(tuple) == 2), "frame_resize should be a tuple of (x,y)"
- self._frame_shape = (1, 3, frame_resize[0], frame_resize[1])
+ if isinstance(frame_resize, (tuple, list)) and (len(frame_resize) == 2):
+ self._frame_resize = tuple(map(int, frame_resize))
+ self._frame_shape = (1, 3, self._frame_resize[0], self._frame_resize[1])
+ elif isinstance(frame_resize, float):
+ width = int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH)*frame_resize)
+ height = int(self._capture.get(cv2.CAP_PROP_FRAME_HEIGHT)*frame_resize)
+ self._frame_shape = (1, 3, width, height)
+ self._frame_resize = (width, height)
+ else:
+ assert False, "frame_resize should be a tuple of (x,y) pixels "
+ "or a float setting the scaling factor"
else:
self._frame_shape = (1, 3,
int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
diff --git a/example/ssd/demo.py b/example/ssd/demo.py
index 4ae8b35..e8194ab 100755
--- a/example/ssd/demo.py
+++ b/example/ssd/demo.py
@@ -109,6 +109,8 @@ def parse_args():
help='string of comma separated names, or text filename')
parser.add_argument('--camera', action='store_true',
help="use camera for image capturing")
+ parser.add_argument('--frame-resize', type=str, default=None,
+ help="resize camera frame to x,y pixels or a float scaling factor")
args = parser.parse_args()
return args
@@ -127,6 +129,15 @@ def parse_class_names(class_names):
raise RuntimeError("No valid class_name provided...")
return class_names
+def parse_frame_resize(x):
+ if not x:
+ return x
+ x = list(map(float, x.strip().split(',')))
+ assert len(x) >= 1 and len(x) <= 2, "frame_resize should be a float scaling factor or a tuple of w,h pixels"
+ if len(x) == 1:
+ x = x[0]
+ return x
+
def parse_data_shape(data_shape_str):
"""Parse string to tuple or int"""
ds = data_shape_str.strip().split(',')
@@ -160,7 +171,7 @@ def network_path(prefix, network, data_shape):
def run_camera(args,ctx):
assert args.batch_size == 1, "only batch size of 1 is supported"
logging.info("Detection threshold is {}".format(args.thresh))
- iter = CameraIterator()
+ iter = CameraIterator(frame_resize=parse_frame_resize(args.frame_resize))
class_names = parse_class_names(args.class_names)
mean_pixels = (args.mean_r, args.mean_g, args.mean_b)
data_shape = int(args.data_shape)
--
To stop receiving notification emails like this one, please contact
zhreshold@apache.org.