-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonoCamera.py
49 lines (37 loc) · 1.55 KB
/
MonoCamera.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
import argparse
from nxlib.context import NxLib, MonoCamera
from nxlib.command import NxLibCommand
from nxlib.constants import *
class MonoCam():
def __init__(self, serial):
self.camera_serial = serial
self.raw_img = None
self.rectified_img = None
def capture_raw(self, filename="raw.png"):
with NxLib(), MonoCamera(self.camera_serial) as camera:
camera.capture()
save_image(filename, camera[ITM_IMAGES][ITM_RAW])
self.raw_img = camera[ITM_IMAGES][ITM_RAW].get_binary_data()
def capture_rectified(self, filename="rectified.png"):
with NxLib(), MonoCamera(self.camera_serial) as camera:
camera.capture()
camera.rectify()
save_image(filename, camera[ITM_IMAGES][ITM_RECTIFIED])
self.rectified_img = camera[ITM_IMAGES][ITM_RECTIFIED].get_binary_data()
def save_image(filename, item):
with NxLibCommand(CMD_SAVE_IMAGE) as cmd:
cmd.parameters()[ITM_NODE] = item.path
cmd.parameters()[ITM_FILENAME] = filename
cmd.execute()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("serial", type=str,
help="the serial of the stereo camera to open")
args = parser.parse_args()
camera_serial = args.serial
# instantiate camera
mono_camera = MonoCam(camera_serial)
# capture and save a raw image
mono_camera.capture_raw("raw_img.png")
# capture and save a rectified image
mono_camera.capture_rectified("rectified_img.png")