From d2bce26df8e2bcc05876a9a602cc2a6ab4ebf1d4 Mon Sep 17 00:00:00 2001 From: Max Value Date: Sat, 25 Oct 2025 01:25:24 +0100 Subject: [PATCH] moved python proj to better place --- cube/__init__.py | 0 {src/cube => cube}/camera.py | 6 +++--- cube/config.py | 7 +++++++ {src/cube => cube}/cube.py | 10 ++++++---- {src/cube => cube}/frame.py | 28 ++++++++++++---------------- {src/cube => cube}/graph.py | 0 {src/cube => cube}/test.py | 7 ++++--- make.py | 23 +++++++++++++++++++++++ requirements.txt | 7 +++++++ src/cube/main.py | 32 -------------------------------- 10 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 cube/__init__.py rename {src/cube => cube}/camera.py (91%) create mode 100644 cube/config.py rename {src/cube => cube}/cube.py (90%) rename {src/cube => cube}/frame.py (68%) rename {src/cube => cube}/graph.py (100%) rename {src/cube => cube}/test.py (93%) create mode 100755 make.py create mode 100644 requirements.txt delete mode 100755 src/cube/main.py diff --git a/cube/__init__.py b/cube/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/cube/camera.py b/cube/camera.py similarity index 91% rename from src/cube/camera.py rename to cube/camera.py index bed2a29..f46caff 100644 --- a/src/cube/camera.py +++ b/cube/camera.py @@ -1,3 +1,5 @@ +from .config import IMAGE_WIDTH, IMAGE_HEIGHT + import numpy as np import cv2 as cv @@ -13,13 +15,11 @@ class Camera(): #self.calibrate() def get(self, image): - import main - cv.imshow("LUT Calibration", image) cv.waitKey(CAP_WAIT) #_, capture = self.camera.read() - #capture = cv.warpPerspective(capture, self.homography, (main.IMAGE_WIDTH, main.IMAGE_HEIGHT)) + #capture = cv.warpPerspective(capture, self.homography, (IMAGE_WIDTH, IMAGE_HEIGHT)) return image return capture diff --git a/cube/config.py b/cube/config.py new file mode 100644 index 0000000..a66128e --- /dev/null +++ b/cube/config.py @@ -0,0 +1,7 @@ +LUT_SIZE = 12 + +IMAGE_WIDTH = 640#1920 +IMAGE_HEIGHT = 360#1080 + +QR_SIZE = 100 +QR_PADDING = 10 diff --git a/src/cube/cube.py b/cube/cube.py similarity index 90% rename from src/cube/cube.py rename to cube/cube.py index dadd661..b89256a 100755 --- a/src/cube/cube.py +++ b/cube/cube.py @@ -1,5 +1,8 @@ #!.venv/bin/python +from .frame import blank, generate, result +from .config import LUT_SIZE + from scipy.interpolate import make_interp_spline from tqdm import tqdm import numpy as np @@ -10,10 +13,10 @@ WAIT_TIME = 0.1 WAIT_TICKS = 100 class Cube(): - def __init__(self, camera, size): + def __init__(self, camera): self.camera = camera - self.size = size - self.lut = np.zeros((size, size, size, 3), dtype=np.uint8) + self.size = LUT_SIZE + self.lut = np.zeros((LUT_SIZE, LUT_SIZE, LUT_SIZE, 3), dtype=np.uint8) self.s = 255 / (self.size-1) print(f""" @@ -81,7 +84,6 @@ colors:\t{self.size**3} self.lut = iter_channels(self.lut) def check(self, color=None): - from frame import blank, generate, result if color is None: image = blank() diff --git a/src/cube/frame.py b/cube/frame.py similarity index 68% rename from src/cube/frame.py rename to cube/frame.py index b8850aa..110bd20 100644 --- a/src/cube/frame.py +++ b/cube/frame.py @@ -1,5 +1,7 @@ #!.venv/bin/python +from .config import QR_SIZE, QR_PADDING, IMAGE_WIDTH, IMAGE_HEIGHT + from pyzbar.pyzbar import decode import numpy as np import cv2 as cv @@ -9,16 +11,14 @@ import os def cast(a): a = np.array(a, dtype=np.float64) - a[...,0] = ((a[...,0] / 255.) ** 0.4) * 255. + a[...,0] = ((a[...,0] / 255.) ** 2) * 255. a[...,1] = ((a[...,1] / 255.) ** 2) * 255. - a[...,2] = ((a[...,2] / 255.) ** 0.3) * 255. + a[...,2] = ((a[...,2] / 255.) ** 2) * 255. a = np.clip(a.astype(np.uint8), 0, 255) return a def generate(color): - import main - # make qr code qr = qrcode.QRCode( version=1, @@ -32,34 +32,30 @@ def generate(color): qr_image = np.array(qr.get_matrix()) qr_image = np.where(qr_image, 0, 255).astype(np.uint8) qr_image = np.repeat(qr_image[:, :, np.newaxis], 3, axis=2) - qr_image = cv.resize(qr_image, (main.QR_SIZE,main.QR_SIZE), interpolation=cv.INTER_NEAREST) + qr_image = cv.resize(qr_image, (QR_SIZE,QR_SIZE), interpolation=cv.INTER_NEAREST) color = cast(color) # create color image of correct shape c_image = np.array([[color[::-1]]], dtype=np.uint8) - c_image = cv.resize(c_image, (main.IMAGE_WIDTH, main.IMAGE_HEIGHT)) + c_image = cv.resize(c_image, (IMAGE_WIDTH, IMAGE_HEIGHT)) # put qr codes in the corners - tl = np.s_[:main.QR_SIZE,:main.QR_SIZE] - tr = np.s_[:main.QR_SIZE,-main.QR_SIZE:] - bl = np.s_[-main.QR_SIZE:,:main.QR_SIZE] - br = np.s_[-main.QR_SIZE:,-main.QR_SIZE:] + tl = np.s_[:QR_SIZE,:QR_SIZE] + tr = np.s_[:QR_SIZE,-QR_SIZE:] + bl = np.s_[-QR_SIZE:,:QR_SIZE] + br = np.s_[-QR_SIZE:,-QR_SIZE:] c_image[tl] = c_image[tr] = c_image[bl] = c_image[br] = qr_image return c_image def blank(): - import main - - image = np.zeros((main.IMAGE_HEIGHT,main.IMAGE_WIDTH,3), dtype=np.uint8) + image = np.zeros((IMAGE_HEIGHT,IMAGE_WIDTH,3), dtype=np.uint8) return image def result(capture): - import main - - l = main.QR_SIZE + main.QR_PADDING + l = QR_SIZE + QR_PADDING new = np.mean(capture[l:-l,l:-l], axis=(0,1)).astype(np.uint8) diff --git a/src/cube/graph.py b/cube/graph.py similarity index 100% rename from src/cube/graph.py rename to cube/graph.py diff --git a/src/cube/test.py b/cube/test.py similarity index 93% rename from src/cube/test.py rename to cube/test.py index f5d0834..f76e0e3 100755 --- a/src/cube/test.py +++ b/cube/test.py @@ -1,13 +1,14 @@ -from frame import cast +from .frame import cast +from .graph import compare + import cv2 as cv import numpy as np -from graph import compare import time def validate(cube): print("testing LUT...") - image = cv.imread("../calibration.jpg") + image = cv.imread("src/calibration.jpg") height, width, _ = image.shape a = cast(np.flip(image, axis=-1)).astype(np.uint8) casted = cast(np.flip(image, axis=-1)).astype(np.uint8) diff --git a/make.py b/make.py new file mode 100755 index 0000000..81232a8 --- /dev/null +++ b/make.py @@ -0,0 +1,23 @@ +#!.venv/bin/python + +from cube.camera import Camera +from cube.graph import show +from cube.test import validate +from cube.cube import Cube + +from numpy import save +import matplotlib.pyplot as plt + +if __name__ == "__main__": + eye = Camera(0) + + lut = Cube(eye) + lut.process() + + show(lut.lut) + + validate(lut) + + save("./cube.npy", lut.lut) + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b5e457 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +matplotlib +opencv-python +numpy +pyzbar +qrcode +scipy +tqdm diff --git a/src/cube/main.py b/src/cube/main.py deleted file mode 100755 index 02dccbd..0000000 --- a/src/cube/main.py +++ /dev/null @@ -1,32 +0,0 @@ -#!.venv/bin/python - -import cube -from camera import Camera -from numpy import save -from graph import show -from test import validate - -import matplotlib.pyplot as plt - -LUT_SIZE = 12 - -IMAGE_WIDTH = 640#1920 -IMAGE_HEIGHT = 360#1080 - -QR_SIZE = 100 -QR_PADDING = 10 - -if __name__ == "__main__": - eye = Camera(0) - - times = [] - means = [] - - lut = cube.Cube(eye, LUT_SIZE) - lut.process() - show(lut.lut) - validate(lut) - - save("../../cube.npy", lut.lut) - - -- 2.39.2