-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathobjectRanging.py
More file actions
46 lines (35 loc) · 985 Bytes
/
objectRanging.py
File metadata and controls
46 lines (35 loc) · 985 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import cv2
import numpy as np
import time
from pal.products.qcar import QCarRealSense, QCar
#------------- functions -------------
def acquire_images(myCam):
myCam.read_RGB()
rgb = myCam.imageBufferRGB
myCam.read_depth()
depth = myCam.imageBufferDepthPX
return rgb, depth
def ranging(depth):
if depth is None:
return None, None
d = np.squeeze(depth)
h, w = d.shape
#uy, ly = h // 3, (2 * h) // 3
uy, ly = 261, 262
lx, rx = w // 3, (2 * w) // 3
crop = d[uy:ly, lx:rx]
obj_dis = np.min(crop)
return crop, obj_dis
#------------- main -------------
myCam = QCarRealSense(mode='RGB, Depth')
try:
while True:
rgb, depth = acquire_images(myCam)
roi, obj_dis = ranging(depth)
print("distane:", obj_dis)
time.sleep(0.1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except KeyboardInterrupt:
print("\nProgram stopped by user (CTRL+C).")
cv2.destroyAllWindows()