-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FPGA Binaries v1.1 with support for AR1335 and OV5647 image sensors * support for AR1335, OV5647 image sensors * video creation script from FPGA Binary ISP output Burst Capture * Kria KV260 Binary file for use with AR1335 IAS image sensor module * Kria KV260 Binary file for use with OV5647 RPi image sensor module * header and description added * header and description added * header and description added * Create sensor_bin_to_sensor_raw_burst_capture.py * header updated * updated video_creation.py * video_creation.py updated * verified with SD card dumps * how to use release v1.1 binaries added --------- Co-authored-by: taimur-10xe <[email protected]> Co-authored-by: talhaiqbal-10xe <[email protected]> Co-authored-by: taimur-10xe <[email protected]>
- Loading branch information
1 parent
dd00e25
commit 0de929f
Showing
8 changed files
with
293 additions
and
447 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
Binary file not shown.
Binary file not shown.
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,90 @@ | ||
""" | ||
File: sensor_bin_to_sensor_raw_burst_capture.py | ||
Description: converts the image sensor memory dumps (.bin) of | ||
RAW Burst Capture from the FPGA Platform to | ||
Bayer RAW frames (.raw) containing valid pixel | ||
data. | ||
It also converts the Bayer RAW frames to | ||
equivalent grayscale .png for visualization. | ||
Author: 10xEngineers | ||
------------------------------------------------------------ | ||
""" | ||
import numpy as np | ||
import matplotlib.image as mpimg | ||
import matplotlib.pyplot as plt | ||
from pathlib import Path | ||
|
||
# Path of the directory containing "OV5467" and "AR1335" directories | ||
path = "./" | ||
|
||
# Supported Sensors and selected sensor (SENSOR) | ||
SupportedSensors = { | ||
"AR1335": 1, | ||
"OV5647": 2 | ||
} | ||
SENSOR = "AR1335" | ||
|
||
# start and end index of burst capture frames for converting .bin to .raw | ||
start, end = 1, 250 | ||
|
||
# parent directory | ||
p = Path(path) | ||
parent_dir = p.resolve().joinpath(SENSOR) | ||
|
||
# Making directories for saving .raw and .png files | ||
raw_dir = "Burst_Capture_RAW" | ||
png_dir = "Burst_Capture_PNG" | ||
bin_dir = "Burst_Capture" # Created by firmware, DO NOT MODIFY | ||
# joining paths with parent directory | ||
raw_path = parent_dir/ raw_dir | ||
Path.mkdir(raw_path, exist_ok=True) | ||
png_path = parent_dir / png_dir | ||
Path.mkdir(png_path, exist_ok=True) | ||
bin_path = parent_dir / bin_dir | ||
|
||
# Selecting height and width based on selected sensor | ||
if(SupportedSensors[SENSOR] == SupportedSensors["AR1335"]): | ||
h, w = 1536, 2048 | ||
|
||
if(SupportedSensors[SENSOR] == SupportedSensors["OV5647"]): | ||
h, w = 1944, 2592 | ||
|
||
h = int(h) | ||
w = int(w) | ||
|
||
# Images are stored in the form of rows where the size of each row in bytes | ||
# should be a multiple of 256, each such row size is called 'stride' | ||
# For raw10 format, 3 pixels are packed into 4 bytes | ||
stride = np.floor(np.floor(np.floor((w+2)/3) *4 +256 - 1) /256) * 256 | ||
stride = stride.astype (np.uint16) | ||
pixelsInStride= int((stride/4)*3) | ||
|
||
for index in range (start, end+1): | ||
# reading the dumped binary file | ||
filename = 'RAW' + str(index) + '.bin' | ||
filepath = bin_path / filename | ||
print('Processing ' + 'RAW'+ str(index) + ' ...') | ||
with open(filepath, 'rb') as f: | ||
# read the contents of the file into a new array | ||
arr = np.fromfile(f, dtype=np.uint8) | ||
|
||
# Reshape the array into groups of 4 elements | ||
grouped_array = arr.reshape(-1, 4) | ||
flipped_array = np.flip(grouped_array, axis=1) | ||
result_list = [] | ||
for inner_array in flipped_array: | ||
# Convert each element to binary and concatenate | ||
binary_concatenated = ''.join([format(x, '08b') for x in inner_array]) | ||
result_list.append((int(binary_concatenated[2:12],2),int(binary_concatenated[12:22],2),int(binary_concatenated[22:32],2))) | ||
img = np.array(result_list).reshape((h, pixelsInStride))[:, 0:w].astype(np.uint16) | ||
|
||
# dumping a .raw file for inf_isp | ||
filename = filename[:-4] | ||
extension = ".raw" | ||
|
||
with open('{}{}'.format(str(raw_path/filename),extension),'wb') as f: | ||
img.tofile(f) | ||
|
||
# dumping a numpy array | ||
img_norm = np.interp(img, (img.min(), img.max()), (0,1023 )).astype(np.uint8) | ||
plt.imshow(img_norm,cmap='gray').write_png(str(png_path/filename) + '.png') |
Oops, something went wrong.