-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLD_001.py
71 lines (54 loc) · 1.86 KB
/
LD_001.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
this file will be used to read map out lanes
"""
# Libraries
import pyrealsense2 as rs
import cv2 as cv
import numpy as np
import helper_rs as h
import sys
# create realsense object
try:
myRS = h.MyRealsense()
except:
sys.exit('COULD NOT CREATE REALSENSE OBJECT')
# configure object
# not needed because these values are the same as the defaults
# this is just to show how to do it
# these parameters must be changed before the realsense is configured
try:
myRS.width = 640
myRS.height = 480
myRS.frame_rate = 30
except:
sys.exit('COULD NOT UPDATE CLASS CONFIGURATIONS')
# configure
if not myRS.MyRealsense_configure():
sys.exit('COULD NOT CONFIGURE REALSENSE')
# start pipeling
if not myRS.MyRealsense_start_pipe():
sys.exit('COULD NOT START PIPELINE')
# wait for shutter lense
if not myRS.MyRealsense_wait_for_lense(5):
myRS.MyRealsense_stop_pipe()
sys.exit('COULD NOT WAIT FOR LENSE TO CONFIGURE')
distance_base = [1.00*10**3]
distance_thresh = [0.05*10**3]
try:
while 1:
color_frame = myRS.MyRealsense_get_color_frame()
depth_frame = myRS.MyRealsense_get_depth_frame()
# filter depth frame
filtered_depth = myRS.MyRealsense_filter_depth(depth_frame, distance_base, distance_thresh)
# erode and dilate frames a bit
# noise reduction
filtered_depth = myRS.MyRealsense_erode_frame(filtered_depth, 1)
# dilate
filtered_depth = myRS.MyRealsense_dilate_frame(filtered_depth, 4)
masked_frame = cv.bitwise_and(color_frame, color_frame, mask=filtered_depth)
combined_frame = np.hstack((color_frame, masked_frame))
cv.namedWindow('RealSense', cv.WINDOW_AUTOSIZE)
cv.imshow('RealSense', combined_frame)
cv.waitKey(1)
finally:
myRS.MyRealsense_stop_pipe()