-
Notifications
You must be signed in to change notification settings - Fork 1
/
tcap.py
60 lines (45 loc) · 1.72 KB
/
tcap.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
55
56
57
58
59
60
#############################################################
## Image Capture Utility for Intel RealSense T265 ##
#############################################################
import pyrealsense2 as rs
import numpy as np
import cv2
import os
from datetime import datetime
# Specify the directory to save the images
save_directory = "/home/pi/Pictures/"
# Initialize the RealSense pipeline
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.fisheye, 1) # Left camera
config.enable_stream(rs.stream.fisheye, 2) # Right camera
# Start the pipeline
pipeline.start(config)
try:
while True:
# Wait for the next set of frames
frames = pipeline.wait_for_frames()
# Get the left and right camera frames
left_frame = frames.get_fisheye_frame(1)
right_frame = frames.get_fisheye_frame(2)
if not left_frame or not right_frame:
continue
# Convert the frames to numpy arrays
left_image = np.asanyarray(left_frame.get_data())
right_image = np.asanyarray(right_frame.get_data())
# Stitch the images horizontally
stitched_image = np.hstack((left_image, right_image))
# Get the current date and time
current_datetime = datetime.now()
timestamp = current_datetime.strftime("%d-%m-%Y_%H:%M:%S")
# Construct the file name
file_name = f"T265_{timestamp}.jpg"
# Save the stitched image to the specified directory
save_path = os.path.join(save_directory, file_name)
cv2.imwrite(save_path, stitched_image)
print(f"Image saved: {save_path}")
# Break the loop after capturing one image
break
finally:
# Stop the pipeline
pipeline.stop()