| import cv2 |
| import os |
| import numpy as np |
|
|
| IMG_SIZE = 256 |
| GOOD_FOLDER = "../dataset/good" |
| OUTPUT_PATH = "reference_bottle.npy" |
|
|
| good_images = [] |
|
|
| for file in os.listdir(GOOD_FOLDER): |
| if file.lower().endswith((".png", ".jpg", ".jpeg")): |
| path = os.path.join(GOOD_FOLDER, file) |
|
|
| img = cv2.imread(path) |
|
|
| if img is None: |
| continue |
|
|
| img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) |
| gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) |
|
|
| good_images.append(gray) |
|
|
| good_images = np.array(good_images) |
|
|
| reference = np.median(good_images, axis=0).astype(np.uint8) |
|
|
| np.save(OUTPUT_PATH, reference) |
|
|
| print("Image de référence sauvegardée :", OUTPUT_PATH) |
|
|