-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.py
54 lines (49 loc) · 1.55 KB
/
sim.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
import argparse
import cv2
import magic_numbers
import numpy as np
from camera_manager import MockImageManager, MockVideoManager, WebcamCameraManager
from connection import DummyConnection
from vision import Vision
parser = argparse.ArgumentParser(
"Simulate code by giving it an image, list of images, video, or camera."
)
parser.add_argument("-v", "--video", help="Use a video")
parser.add_argument(
"-i",
"--image",
nargs="+",
help="Specify an image or list of images. for example, `sim.py --image foo.jpg bar.jpg",
)
parser.add_argument(
"-c",
"--camera",
help="Use a camera. Must be followed by a camera number. For example, most webcams would be 0.",
)
args = parser.parse_args()
if args.image:
print(f"IMAGE: {args.image}")
frame = np.zeros(
shape=(magic_numbers.FRAME_HEIGHT, magic_numbers.FRAME_WIDTH, 3), dtype=np.uint8
)
current_image = 0
camera_manager = MockImageManager(frame, display_output=True)
elif args.video:
print(f"VIDEO: {args.video}")
camera_manager = MockVideoManager(cv2.VideoCapture(args.video), display_output=True)
elif args.camera:
print(f"CAMERA: {args.camera}")
camera_manager = WebcamCameraManager(int(args.camera))
else:
parser.print_help()
quit()
connection = DummyConnection()
vision = Vision(camera_manager, connection)
while True:
if args.image:
frame = cv2.imread(args.image[current_image])
camera_manager.change_image(frame)
vision.run()
current_image += 1
if current_image == len(args.image):
exit()