I tried to use hardware isp in beagley ai. But its failing again and again.
I was able to capture raw image from the imx219 sensor in bayer format and processed it using a python script.
When i tried checking available hardware. I was able to confirm the availability of jpeg encoder e5010 , wave5 decoder.
There seems to not be any driver for ISP to convert bayer format, no h.264 or hevc encoder drivers.
Does anyone know how can i find these drivers and activate them (if already present in BeagleY-AI Debian 12.9 2025-03-05 XFCE (v6.6.x-ti) image ) or how can i import them into beagley ai.
import rawpy
import imageio
import numpy as np
# --- Configuration ---
raw_file_path = 'your_image.raw' # Replace with the path to your .raw file
jpeg_file_path = 'output_image.jpeg' # Replace with the desired output JPEG path
image_height = 1080
image_width = 1920
# Bayer pattern (for rawpy, often auto-detected, but good to know)
# 0=RGGB, 1=GRBG, 2=GBRG, 3=BGGR (Check your camera/sensor spec if unsure)
# 'RGGB' corresponds to pattern 0 typically.
try:
# --- Using rawpy (Recommended for camera RAW files) ---
print(f"Attempting to read RAW file: {raw_file_path} using rawpy")
with rawpy.imread(raw_file_path) as raw:
print("RAW file read successfully. Post-processing...")
# postprocess() handles demosaicing, color correction, etc.
# use_camera_wb=True tries to use the white balance from the camera metadata
# output_bps=8 sets the output bit depth to 8 for JPEG compatibility
rgb_image = raw.postprocess(use_camera_wb=True, output_bps=8)
# Check if the output dimensions match (rawpy might auto-detect)
print(f"Processed image dimensions: {rgb_image.shape}")
if rgb_image.shape[0] != image_height or rgb_image.shape[1] != image_width:
print(f"Warning: Processed dimensions ({rgb_image.shape[0]}x{rgb_image.shape[1]}) differ from expected ({image_height}x{image_width}).")
print(f"Saving processed image to: {jpeg_file_path}")
imageio.imwrite(jpeg_file_path, rgb_image, quality=95) # Adjust quality (0-100) as needed
print("JPEG image saved successfully.")
except rawpy.LibRawNoMetadataError:
print("rawpy couldn't find metadata. The file might be headerless raw data.")
print("Attempting manual read with NumPy and OpenCV...")
# --- Fallback for Headerless RAW Data (Requires OpenCV) ---
# You might need: pip install opencv-python
import cv2
try:
print("Reading raw data with NumPy...")
# Assuming 8-bit raw data for simplicity. Adjust dtype if it's 10-bit, 12-bit, 16-bit etc.
# e.g., np.uint16 for 16-bit. You might need specific unpacking for packed formats (like 10/12-bit).
bayer_data = np.fromfile(raw_file_path, dtype=np.uint8).reshape((image_height, image_width))
print("Demosaicing using OpenCV (RGGB pattern)...")
# Use cv2.COLOR_BAYER_RG2BGR for RGGB pattern
# Other patterns include: _BG, _GB, _GR
rgb_image_cv = cv2.cvtColor(bayer_data, cv2.COLOR_BAYER_RG2BGR)
print(f"Saving processed image to: {jpeg_file_path}")
# OpenCV uses BGR order, imwrite handles it correctly for JPEG
cv2.imwrite(jpeg_file_path, rgb_image_cv, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
print("JPEG image saved successfully using OpenCV.")
except ImportError:
print("Error: OpenCV is required for the fallback method. Please install it: pip install opencv-python")
except Exception as e:
print(f"Error processing headerless RAW data: {e}")
except FileNotFoundError:
print(f"Error: Input file not found at {raw_file_path}")
except Exception as e:
print(f"An unexpected error occurred: {e}")