54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import argparse
|
|
|
|
import usb.core
|
|
|
|
import driver
|
|
|
|
|
|
def get_argparser():
|
|
parser = argparse.ArgumentParser(description="ASI USB driver")
|
|
parser.add_argument("--init", action="store_true")
|
|
parser.add_argument("--capture")
|
|
parser.add_argument("--preview", action="store_true")
|
|
parser.add_argument("--exposure", default=100000, type=int)
|
|
parser.add_argument("--brightness", default=0, type=int)
|
|
parser.add_argument("--width", default=1920, type=int)
|
|
parser.add_argument("--height", default=1080, type=int)
|
|
parser.add_argument("--startx", default=0, type=int)
|
|
parser.add_argument("--starty", default=0, type=int)
|
|
parser.add_argument("--depth", default=8, type=int, choices=[8, 16])
|
|
parser.add_argument("--temp", action="store_true")
|
|
parser.add_argument("--win_width", type=int, default=1280)
|
|
parser.add_argument("--win_height", type=int, default=720)
|
|
return parser
|
|
|
|
|
|
def main():
|
|
args = get_argparser().parse_args()
|
|
devices = usb.core.find(find_all=True, idVendor=0x3C3, idProduct=0x662C)
|
|
dev = next(devices)
|
|
dev.set_configuration()
|
|
cam = driver.ASI662MM(dev)
|
|
if args.init:
|
|
cam.init_camera()
|
|
if args.init or args.capture or args.preview:
|
|
cam.set_roi(args.width, args.height, args.startx, args.starty)
|
|
cam.set_exposure(args.exposure)
|
|
cam.init_sensor_mode(1, 1 if args.depth == 16 else 0, 0)
|
|
cam.set_brightness(args.brightness)
|
|
if args.capture:
|
|
img = cam.take_picture()
|
|
with open(args.capture, "wb") as f:
|
|
f.write(img)
|
|
if args.temp:
|
|
print(cam.get_temperature())
|
|
if args.preview:
|
|
import preview
|
|
|
|
assert args.depth == 8, "preview only supports 8 bit depth"
|
|
preview.run(cam, args.win_width, args.win_height)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|