File size: 693 Bytes
a966d70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)