From 91baba6cc49643957e1af55f864800d58e8f2e6e Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Fri, 29 Sep 2023 22:40:46 +0200 Subject: [PATCH] added file --- src/experiments/algorithms/colour_FE.py | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/experiments/algorithms/colour_FE.py diff --git a/src/experiments/algorithms/colour_FE.py b/src/experiments/algorithms/colour_FE.py new file mode 100644 index 0000000..ce6c0f9 --- /dev/null +++ b/src/experiments/algorithms/colour_FE.py @@ -0,0 +1,83 @@ +import cv2 +import cv2.typing +from cv2.mat_wrapper import Mat as Mat +import os +import numpy as np +import csv + +CSV_PATH = "src\\experiments\\algorithms\\data\\" +IMG_PATH = "dataset\\accasia_1210048 (2023_09_28 12_19_26 UTC).JPG" +BARK_TYPES = 8 + +class colourTester: + def __init__(self) -> None: + pass + + def loadImage(self) -> None: + img = cv2.imread(self.im_path, 1) + assert img is not None, \ + "Failed to load an image, check path" + self.img = img + return + + def setImPath(self, path : str) -> None: + if os.path.isfile(path): + self.im_path = path + else: + print("file does not exist") + return + + def setCsvBgrPath(self, path : str) -> None: + if os.path.isfile(path): + self.csv_bgr_path = path + else: + print("file does not exist") + return + + def setCsvHsvPath(self, path : str) -> None: + if os.path.isfile(path): + self.csv_hsv_path = path + else: + print("file does not exist") + return + + def getData(self, img : cv2.typing.MatLike) -> (float, float): + mean = np.zeros(3) + std = np.zeros(3) + for i in range(img.shape[2]): + mean[i] = np.mean(img[:, :, i]) + std[i] = np.std(img[:, :, i]) + return (mean, std) + + def loadCurves(self) -> None: + labels = [] + ids = [] + data = [[[], [], []] for x in range(BARK_TYPES)] + with open(self.csv_bgr_path, 'r') as bgr_file: + reader = csv.reader(bgr_file, delimiter=',') + # fix whatever is happening here + + print(data) + return + + def testImage(self) -> None: + # load an image + self.loadImage() + + # load curves + self.loadCurves() + + # extract data + mean, std = self.getData(self.img) + + # correlate with curves + # dictionary? list? with 0 - 1 scores + pass + +if __name__ == "__main__": + tester = colourTester() + tester.setImPath(IMG_PATH) + tester.setCsvBgrPath(CSV_PATH + "bgr_curve.csv") + tester.setCsvHsvPath(CSV_PATH + "hsv_curve.csv") + tester.testImage() + pass \ No newline at end of file