import cv2 import numpy as np import os import shutil def fix_minimap_center(): # Paths artifacts_dir = '/Users/davidkotnik/.gemini/antigravity/brain/07019d04-a214-43ab-9565-86f4e8f17e5b' # Find latest minimap artifact minimap_src = None candidates = [] for f in os.listdir(artifacts_dir): if 'ui_minimap_frame' in f and f.endswith('.png'): candidates.append(os.path.join(artifacts_dir, f)) if not candidates: print("Minimap artifact not found in brain.") return candidates.sort(key=os.path.getmtime, reverse=True) minimap_src = candidates[0] # Load image print(f"Fixing {minimap_src}") img = cv2.imread(minimap_src, cv2.IMREAD_UNCHANGED) # If no alpha, add it if img.shape[2] == 3: img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA) # 1. Remove Magenta Background (as before) target = np.array([255, 0, 255]) tol = 60 lower = np.clip(target - tol, 0, 255) upper = np.clip(target + tol, 0, 255) mask_bg = cv2.inRange(img[:,:,:3], lower, upper) img[mask_bg > 0, 3] = 0 # 2. REMOVE CHECKERBOARD CENTER # The checkerboard is usually gray/white pixels. # Gray: (204, 204, 204), White: (255, 255, 255) or similar. # We can detect pixels that are essentially grayscale (R~=G~=B) and high brightness. # Convert to HSV to check saturation? hsv = cv2.cvtColor(img[:,:,:3], cv2.COLOR_BGR2HSV) s = hsv[:,:,1] v = hsv[:,:,2] # Checkerboard is low saturation (gray/white) and high value # Define mask for "grayish/whiteish stuff" # S < 20 (very low color) # V > 150 (fairly bright) mask_center = (s < 30) & (v > 150) # But wait, the metal rim is also gray! # We only want to remove the CENTER. # Let's use a circular mask for the center hole. h, w = img.shape[:2] center_x, center_y = w // 2, h // 2 # Radius of the inner hole? # Based on the image, the rim is maybe 15-20% of radius. # Let's guess inner radius is about 75% of total width/2. radius = int((w / 2) * 0.72) # Create circular mask circle_mask = np.zeros((h, w), dtype=np.uint8) cv2.circle(circle_mask, (center_x, center_y), radius, 255, -1) # Combine masks: Must be inside the circle AND be gray/checkerboard-like # Actually, simpler: JUST CUT THE HOLE. # If the user wants a transparent center, we can just clear everything inside the metal ring. # The metal ring has content. The center is just checkerboard. # Let's force alpha=0 for the inner circle. # Refined approach: # Everything inside the circle_mask becomes transparent. img[circle_mask > 0, 3] = 0 # Resizing to standard size target_w = 256 scale = target_w / w new_h = int(h * scale) img = cv2.resize(img, (target_w, new_h), interpolation=cv2.INTER_AREA) # Save and Deploy dest_name = 'minimap_frame.png' targets = [ '/Users/davidkotnik/repos/novafarma/main/assets', '/Users/davidkotnik/repos/novafarma/assets/DEMO_FAZA1/UI', '/Users/davidkotnik/nova farma/main/assets' ] for t in targets: final_path = os.path.join(t, dest_name) cv2.imwrite(final_path, img) print(f"Saved fixed minimap to {final_path}") if __name__ == "__main__": fix_minimap_center()