-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_detection_image_viewer.py
73 lines (58 loc) · 2.47 KB
/
object_detection_image_viewer.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
72
73
import sys
import ogl_viewer.viewer as gl
import pyzed.sl as sl
if __name__ == "__main__":
# Create a Camera object
zed = sl.Camera()
# Create a InitParameters object and set configuration parameters
init_params = sl.InitParameters()
init_params.camera_resolution = sl.RESOLUTION.HD720 # Use HD720 video mode
init_params.coordinate_units = sl.UNIT.METER
init_params.camera_fps = 15 # Set fps at 15
init_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP
# If applicable, use the SVO given as parameter
# Otherwise use ZED live stream
if len(sys.argv) == 2:
filepath = sys.argv[1]
print("Using SVO file: {0}".format(filepath))
init_params.set_from_svo_file(filepath)
# Set runtime parameters
runtime_parameters = sl.RuntimeParameters()
# Open the camera
err = zed.open(init_params)
if err != sl.ERROR_CODE.SUCCESS:
exit(1)
# Enable object detection module
obj_param = sl.ObjectDetectionParameters()
# Defines if the object detection will track objects across images flow.
obj_param.enable_tracking = True # if True, enable positional tracking
if obj_param.enable_tracking:
zed.enable_positional_tracking()
zed.enable_object_detection(obj_param)
camera_info = zed.get_camera_information()
# Create OpenGL viewer
viewer = gl.GLViewer()
viewer.init(camera_info.calibration_parameters.left_cam)
# Configure object detection runtime parameters
obj_runtime_param = sl.ObjectDetectionRuntimeParameters()
obj_runtime_param.detection_confidence_threshold = 50
#obj_runtime_param.object_class_filter = [sl.OBJECT_CLASS.PERSON] # Only detect Persons
print(obj_runtime_param.object_class_filter)
# Create ZED objects filled in the main loop
objects = sl.Objects()
image = sl.Mat()
while viewer.is_available():
# Grab an image, a RuntimeParameters object must be given to grab()
if zed.grab(runtime_parameters) == sl.ERROR_CODE.SUCCESS:
# Retrieve left image
zed.retrieve_image(image, sl.VIEW.LEFT)
# Retrieve objects
zed.retrieve_objects(objects, obj_runtime_param)
# Update GL view
viewer.update_view(image, objects)
viewer.exit()
image.free(memory_type=sl.MEM.CPU)
# Disable modules and close camera
zed.disable_object_detection()
zed.disable_positional_tracking()
zed.close()