55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import cv2
|
|
import numpy as np
|
|
import os
|
|
import shutil
|
|
|
|
def process_stream_image():
|
|
src_path = '/Users/davidkotnik/.gemini/antigravity/brain/07019d04-a214-43ab-9565-86f4e8f17e5b/uploaded_media_1769595145566.jpg'
|
|
|
|
# 1. Load Image
|
|
print(f"Loading {src_path}")
|
|
img = cv2.imread(src_path)
|
|
if img is None:
|
|
print("Failed to load image")
|
|
return
|
|
|
|
# 2. Remove Background
|
|
# Convert to BGRA
|
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
|
|
|
|
# The background is a very uniform light gray.
|
|
# Let's sample the corner (0,0)
|
|
bg_color = img[0,0][:3]
|
|
print(f"Detected BG Color: {bg_color}")
|
|
|
|
# Create mask range
|
|
tol = 30
|
|
lower = np.clip(bg_color - tol, 0, 255)
|
|
upper = np.clip(bg_color + tol, 0, 255)
|
|
|
|
mask = cv2.inRange(img[:,:,:3], lower, upper)
|
|
|
|
# Set alpha to 0 where mask is present
|
|
img[mask > 0, 3] = 0
|
|
|
|
# 3. Save to Game Assets
|
|
dest_path = '/Users/davidkotnik/repos/novafarma/main/assets/stream_winding.png'
|
|
cv2.imwrite(dest_path, img)
|
|
print(f"Saved processed asset to {dest_path}")
|
|
|
|
# Sync to other locations just in case
|
|
shutil.copy2(dest_path, '/Users/davidkotnik/nova farma/main/assets/stream_winding.png')
|
|
|
|
# 4. Save Reference (Try to copy original)
|
|
try:
|
|
ref_dir = '/Users/davidkotnik/repos/novafarma/main/assets/references'
|
|
if not os.path.exists(ref_dir):
|
|
os.makedirs(ref_dir)
|
|
shutil.copy2(src_path, os.path.join(ref_dir, 'umazan_potok_ref.jpg'))
|
|
print("Saved reference copy.")
|
|
except Exception as e:
|
|
print(f"Failed to save reference copy: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
process_stream_image()
|