-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinDepthRealsenseROS.py
33 lines (27 loc) · 1.02 KB
/
MinDepthRealsenseROS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from sys import stdout
import cv2
class MinDepthRealsenseROS:
LogFilename="realsense.log"
DepthUnitMeters = 0.001
def __init__(self):
loggerHandlers = [
logging.StreamHandler(stream=stdout),
#logging.FileHandler(filename=MinDepthRealsenseROS.LogFilename)
]
logging.basicConfig(handlers=loggerHandlers, level=logging.DEBUG)
def setRoi(self, left, right, top, bottom):
self.left = left
self.right = right
self.top = top
self.bottom = bottom
def processDepthImage(self, numpyImage):
try:
numpyCrop = numpyImage[self.top:self.bottom, self.left:self.right]
minVal, maxVal, minPos, maxPos = cv2.minMaxLoc(numpyCrop)
minDepth = minVal * MinDepthRealsenseROS.DepthUnitMeters
logging.debug('Process frame : min depth {1} m at {2}'.format(minDepth, minPos))
return minDepth
except Exception as e:
logging.error(e)
return -1