-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcam-server.py
executable file
·54 lines (42 loc) · 1.99 KB
/
rcam-server.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
#!/usr/bin/env python3
import argparse
import zmq
import rcam
from rcam.server import Server
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--api-port', help='port to bind api to', type=int, default=8089)
parser.add_argument('-c', '--camera-id', help='the camera to connect to', type=int, default=0)
parser.add_argument('-m', '--mode', help='the camera mode', type=int, default=2)
parser.add_argument('-f', '--max-fps', help='the maximum fps', type=int, default=0)
parser.add_argument('-e', '--exposure-time', help='the exposure time in microseconds', type=int, default=0)
parser.add_argument('-g', '--analogue-gain', help='the analogue gain', type=float, default=0.0)
parser.add_argument('--hflip', help='flip the image horizontally', action='store_true')
parser.add_argument('--vflip', help='flip the image vertically', action='store_true')
parser.add_argument('--preview', help='run the camera preview on attached monitor', action='store_true')
parser.add_argument('--tuning-file', help='specify a tuning file override', type=str, default=None)
group = parser.add_mutually_exclusive_group()
group.add_argument('--rl8', help='send raw linear 8bit image', action='store_true')
group.add_argument('--rg8', help='send raw gamma encoded 8bit image', action='store_true')
args = parser.parse_args()
api_url = f"tcp://0.0.0.0:{args.api_port}"
pub_url = f"tcp://0.0.0.0:{args.api_port+1}"
urls = rcam.connect_urls(api_url)
for u in urls:
print(f"listening at {u}")
kwargs = vars(args)
del kwargs['api_port']
dtype = 'rl8' if args.rl8 else 'rg8' if args.rg8 else 'rgb'
del kwargs['rl8']
del kwargs['rg8']
kwargs['dtype'] = dtype
context = zmq.Context()
svr = Server(context, api_url, pub_url, **kwargs)
svr.start()
try:
svr.join()
except KeyboardInterrupt:
svr.set_over()
svr.join()
if __name__ == "__main__":
main()