-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2f6cf8
commit da4e198
Showing
6 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import cv2 | ||
import os | ||
|
||
def save_image(image, prefix, index, subfolder='depth_png'): | ||
directory = os.path.join(os.getcwd(), subfolder) | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
filename = f"{prefix}_{index}.png" | ||
filepath = os.path.join(directory, filename) | ||
cv2.imwrite(filepath, image) | ||
print(f"Saved {filename} to {subfolder}/") | ||
|
||
def process_depth_image(image_path, output_index): | ||
# Load the depth image | ||
depth_image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED) # Make sure to load it in the original bit depth | ||
|
||
# Normalize the depth image | ||
depth_image_normalized = cv2.normalize(depth_image, None, 0, 255, cv2.NORM_MINMAX) | ||
|
||
# Convert to 8-bit | ||
depth_image_8bit = cv2.convertScaleAbs(depth_image_normalized) | ||
|
||
# Save the 8-bit depth image | ||
save_image(depth_image_8bit, 'depth', output_index) | ||
|
||
# Example usage | ||
process_depth_image('/home/miguel/Documents/BEP-Testing/Test Case 1/Frames Sat Jun 29 Test Case 1/depth/depth_000422.png' , 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import cv2 | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
# Path to the folder containing frames | ||
folder_path = '/home/miguel/Documents/BEP-Testing/Test Case 1/Frames Sat Jun 29 Test Case 1/rgb' | ||
|
||
# Frame rate of the video | ||
frame_rate = 18.7 | ||
|
||
# Get list of all frames | ||
frames = sorted([os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith('.png')]) | ||
|
||
# Parameters for selecting frames | ||
total_frames = len(frames) | ||
selected_frame_indices = np.linspace(0, total_frames-1, 12, dtype=int) # Select 12 evenly spaced frames | ||
|
||
# List to store selected frames | ||
selected_frames = [] | ||
|
||
for i in selected_frame_indices: | ||
# Read the frame | ||
frame = cv2.imread(frames[i]) | ||
|
||
# Convert BGR to RGB | ||
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | ||
|
||
# Calculate timestamp | ||
timestamp = i / frame_rate | ||
|
||
# Put timestamp on frame | ||
font = cv2.FONT_HERSHEY_SIMPLEX | ||
text = f'{timestamp:.1f}' | ||
text_size = cv2.getTextSize(text, font, 1.5, 2)[0] | ||
text_x = frame_rgb.shape[1] - text_size[0] - 10 | ||
text_y = 40 | ||
cv2.putText(frame_rgb, text, (text_x, text_y), font, 1.5, (0, 0, 0), 3, cv2.LINE_AA) | ||
|
||
# Append frame to the list | ||
selected_frames.append(frame_rgb) | ||
|
||
# Determine grid size for subplot | ||
rows = int(np.ceil(len(selected_frames) / 4)) | ||
cols = 4 | ||
|
||
# Plot frames in a grid | ||
fig, axes = plt.subplots(rows, cols, figsize=(20, 5*rows)) | ||
axes = axes.flatten() | ||
|
||
for ax, frame in zip(axes, selected_frames): | ||
ax.imshow(frame) | ||
ax.axis('off') | ||
|
||
# Hide any remaining empty subplots | ||
for i in range(len(selected_frames), rows * cols): | ||
fig.delaxes(axes[i]) | ||
|
||
plt.tight_layout() | ||
plt.savefig('composite_image.png') | ||
plt.show() |