JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
PyPostDepth.py
Go to the documentation of this file.
1import pyjevois
2if pyjevois.pro: import libjevoispro as jevois
3else: import libjevois as jevois
4
5import numpy as np
6
7## Python DNN post-processor for depth map
8#
9# Renders a depth map as a semi-transparent overlay over the input frames.
10#
11# @author Laurent Itti
12#
13# @email itti\@usc.edu
14# @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
15# @copyright Copyright (C) 2023 by Laurent Itti, iLab and the University of Southern California
16# @mainurl http://jevois.org
17# @supporturl http://jevois.org/doc
18# @otherurl http://iLab.usc.edu
19# @license GPL v3
20# @distribution Unrestricted
21# @restrictions None
22# @ingroup pydnn
24 # ###################################################################################################
25 ## Constructor
26 def __init__(self):
27 self.depthmap = None
28
29 # ###################################################################################################
30 ## JeVois parameters initialization
31 def init(self):
32 pc = jevois.ParameterCategory("DNN Post-Processing Options", "")
33
34 self.alpha = jevois.Parameter(self, 'alpha', 'byte',
35 "Alpha value for depth overlay",
36 200, pc)
37
38 self.dfac = jevois.Parameter(self, 'dfac', 'float',
39 "Depth conversion factor to bring values to [0..255]",
40 50, pc)
41
42 # ###################################################################################################
43 ## Get network outputs
44 def process(self, outs, preproc):
45 if len(outs) != 1: jevois.LERROR(f"Received {len(outs)} network outputs -- USING FIRST ONE")
46 dmap = (np.squeeze(outs[0]) * self.dfac.get()).clip(0, 255).astype('uint8')
47
48 # Compute overlay corner coords within the input image, for use in report():
49 self.tlx, self.tly, self.cw, self.ch = preproc.getUnscaledCropRect(0)
50
51 # Save RGBA depth map for later display:
52 alphamap = np.full_like(dmap, self.alpha.get())
53 self.depthmap = np.dstack( (dmap, dmap, dmap, alphamap) ) # RGBA
54
55 # ###################################################################################################
56 ## Report the latest results obtained by process() by drawing them
57 def report(self, outimg, helper, overlay, idle):
58
59 if helper is not None and overlay and self.depthmap is not None:
60 # Convert box coords from input image to display ("c" is the displayed camera image):
61 tl = helper.i2d(self.tlx, self.tly, "c")
62 wh = helper.i2ds(self.cw, self.ch, "c")
63
64 # Draw as a semi-transparent overlay. OpenGL will do scaling/stretching/blending as needed:
65 helper.drawImage("depthmap", self.depthmap, True, int(tl.x), int(tl.y), int(wh.x), int(wh.y), False, True)
Python DNN post-processor for depth map.
__init__(self)
Constructor.
process(self, outs, preproc)
Get network outputs.
report(self, outimg, helper, overlay, idle)
Report the latest results obtained by process() by drawing them.
init(self)
JeVois parameters initialization.