import cv2
import numpy as np

def img_to_ascii(image, max_w=120):
    if isinstance(image, str):
        image = cv2.imread(image)
    if image is None: return
    
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) if len(image.shape) == 3 else image
    h, w = gray.shape
    scale = max_w / w
    resized = cv2.resize(gray, (max_w, int(h * scale)))
    
    chars = " .:-=+*#%@"
    for r in range(resized.shape[0]):
        row_str = ""
        for c in range(resized.shape[1]):
            val = resized[r, c]
            idx = int((val / 255.0) * (len(chars) - 1))
            row_str += chars[idx]
        print(row_str)

if __name__ == "__main__":
    img = cv2.imread("C:/Users/Certes/.gemini/antigravity/brain/975cea00-dd68-4689-9ee3-f1a2408b4ee6/verify_pano_chunk_00.png")
    cv2.imwrite("C:/Users/Certes/.gemini/antigravity/brain/975cea00-dd68-4689-9ee3-f1a2408b4ee6/verify_first_measure.png", img[:50, :200])
    
    print("Exported verify_first_measure.png from verify_pano_chunk_00.png")
    
    print("Exported verify_first_measure.png from raw_frame_1920.png")


