Author: Hakan Ardo <ha...@debian.org> Branch: extradoc Changeset: r4800:f482dd01f80d Date: 2012-09-12 17:06 +0200 http://bitbucket.org/pypy/extradoc/changeset/f482dd01f80d/
Log: some morphology diff --git a/talk/dls2012/demo/analytics.py b/talk/dls2012/demo/analytics.py --- a/talk/dls2012/demo/analytics.py +++ b/talk/dls2012/demo/analytics.py @@ -3,6 +3,7 @@ from io import view from background import Background from foreground import foreground +from detect import find_objects class Tracker(ReloadHack): def __init__(self): @@ -12,5 +13,6 @@ self.background.update(frame) fg = foreground(frame, self.background.image) #view(self.background.image) + find_objects(fg) view(255 * fg) diff --git a/talk/dls2012/demo/detect.py b/talk/dls2012/demo/detect.py new file mode 100644 --- /dev/null +++ b/talk/dls2012/demo/detect.py @@ -0,0 +1,41 @@ +from reloader import autoreload +from io import view + +def morph(fg, r, fn): + res = fg.new() + for y in xrange(fg.height): + for x in xrange(fg.width): + #res[x, y] = max(fg[x+dx, y+dy] + # for dx in xrange(-r, r+1) + # for dy in xrange(-r, r+1)) + res[x, y] = fg[x, y] + for dx in xrange(-r, r+1): + for dy in xrange(-r, r+1): + res[x, y] = fn(res[x, y], fg[x+dx, y+dy]) + return res + +def morph(fg, r, fn): + xres = fg.new() + for y in xrange(fg.height): + for x in xrange(fg.width): + xres[x, y] = fg[x, y] + for dx in xrange(-r, r+1): + xres[x, y] = fn(xres[x, y], fg[x+dx, y]) + res = fg.new() + for y in xrange(fg.height): + for x in xrange(fg.width): + res[x, y] = xres[x, y] + for dy in xrange(-r, r+1): + res[x, y] = fn(res[x, y], xres[x, y+dy]) + return res + +def erode(fg, r=1): + return morph(fg, r, min) + +def dilate(fg, r=1): + return morph(fg, r, max) + +@autoreload +def find_objects(fg): + seg = erode(dilate(fg, 3), 4) + view(255*seg, 'd') diff --git a/talk/dls2012/demo/image.py b/talk/dls2012/demo/image.py --- a/talk/dls2012/demo/image.py +++ b/talk/dls2012/demo/image.py @@ -19,6 +19,7 @@ def __init__(self, w, h, typecode='d', data=None): self.width = w self.height = h + self.typecode = typecode if data is None: self.data = array(typecode, [0]) * (w*h) else: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit