-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVideo_Stream_Receiver.py
More file actions
55 lines (51 loc) · 2.11 KB
/
Copy pathVideo_Stream_Receiver.py
File metadata and controls
55 lines (51 loc) · 2.11 KB
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
import sys
import cv2
import ASDP_Core as asdp
def run_server(name, serial, camera_id, frame_stride, replay_id):
# Construct using the appropriate parameters
if serial is not None:
# Connect to live stream
receiver = asdp.VideoStreamReceiver(name, serial, camera_id, frame_stride, replay_id)
else:
# Connect to replay stream
receiver = asdp.VideoStreamReceiver(name)
# Receive a frame (this would be done in a loop for a real application)
frame = receiver.GetNextFrame(5000000) # Timeout of 5 seconds
# If the tuple is empty, we timed out.
if frame is None or len(frame) == 0:
print("Timed out waiting for frame.")
else:
sec = frame[0].seconds
usec = frame[0].microseconds
print("Received frame from time", sec, ":", usec)
# Write the numpy array to a file as an image.
if frame[1].dtype != 'uint16':
print("Frame data type is not uint16, cannot write image.")
if frame[1].ndim != 2:
print("Frame data is not 2D/mono, cannot write image.")
fileName = "received_frame.png"
print("Writing", fileName)
# Use PNG (lossless, supports 16-bit) or TIFF by file extension.
cv2.imwrite(fileName, frame[1])
# Parse when executed as script
if __name__ == "__main__" or "pytest" not in sys.modules:
# If we have command-line arguments, use the first as the URL.
if len(sys.argv) == 2:
name = sys.argv[1]
serial = None
camera_id = None
frame_stride = None
replay_id = None
elif len(sys.argv) == 6:
name = sys.argv[1]
serial = int(sys.argv[2])
camera_id = int(sys.argv[3])
frame_stride = int(sys.argv[4])
replay_id = int(sys.argv[5])
else:
print("Usage: python Video_Stream_Receiver.py [ fileName | serverIP serial cameraID frameStride replayID ]")
sys.exit(1)
run_server(name, serial, camera_id, frame_stride, replay_id)
else:
# When imported as a module, default to None; callers can pass parameters explicitly.
pass