-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator_tester.py
78 lines (68 loc) · 3.06 KB
/
generator_tester.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
74
75
76
77
78
import argparse
import numpy as np
import time
import cv2
from depth_data_generator import DepthDataGenerator
from image_generator import ImageGenerator
from video_live_generator import VideoLiveGenerator
from video_file_generator import VideoFileGenerator
parser = argparse.ArgumentParser()
parser.add_argument("generator", help="choices = [DepthDataGenerator, DepthLiveGenerator, ImageGenerator, VideoLiveGenerator, VideoFileGenerator]")
parser.add_argument("--destination", nargs="?", help="path of the file to save the results to")
parser.add_argument("--depth", nargs="?", help="path of the CSV file to read")
parser.add_argument("--image", nargs="?", help="path of the image file to read")
parser.add_argument("--video", nargs="?", help="path of the video file to read")
parser.add_argument("--play", action="store_true", help="specify whether or not to play live feeds or videos")
args = parser.parse_args()
if args.generator == "DepthDataGenerator":
depth_data_generator = DepthDataGenerator(args.depth, args.image)
rgb, depth = depth_data_generator.generate()
np.savetxt(args.destination, depth, delimiter=",", fmt="%s")
elif args.generator == "DepthLiveGenerator":
from depth_live_generator import DepthLiveGenerator
depth_live_generator = DepthLiveGenerator(2)
if not args.play:
print("The tester will collect data after five seconds")
time.sleep(5)
rgb, depth = depth_live_generator.generate()
if args.destination is not None:
np.savetxt(args.destination, depth, delimiter=",", fmt="%s")
else:
print("Playing camera feed. Press \'q\' to quit")
while True:
bgr, depth = depth_live_generator.generate()
cv2.imshow("Video", bgr)
cv2.imshow("Depth", depth)
key = cv2.waitKey(1)
if key == ord('c') and args.destination is not None:
np.savetxt(args.destination, depth, delimiter=",", fmt="%s")
if key == ord('q'):
break
elif args.generator == "ImageGenerator":
image_generator = ImageGenerator(args.image)
rgb, depth = image_generator.generate()
print(rgb.shape)
elif args.generator == "VideoLiveGenerator":
video_live_generator = VideoLiveGenerator(1)
rgb, depth = video_live_generator.generate()
print(rgb.shape)
if args.play:
print("Playing camera feed. Press \'q\' to quit")
while True:
rgb, _ = video_live_generator.generate()
cv2.imshow("Live video", cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR))
key = cv2.waitKey(1)
if key == ord('q'):
break
elif args.generator == "VideoFileGenerator":
video_file_generator = VideoFileGenerator(args.video)
rgb, depth = video_file_generator.generate()
print(rgb.shape)
if args.play:
print("Playing camera feed. Press \'q\' to quit")
while True:
rgb, _ = video_file_generator.generate()
cv2.imshow("Video", cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR))
key = cv2.waitKey(1)
if key == ord('q'):
break