]> OzVa Git service - audio-over-stft/commitdiff
- Added VideoCapture thread class to continuously capture frames
authorwill <greenwoodw50@gmail.com>
Mon, 5 Aug 2024 18:01:19 +0000 (19:01 +0100)
committerwill <greenwoodw50@gmail.com>
Mon, 5 Aug 2024 18:01:19 +0000 (19:01 +0100)
- Built vingette and color lookup table generator
- Tweaks to the looper file (loop.py)

__pycache__/camera.cpython-311.pyc
camera.py
lookup_color.npy [new file with mode: 0644]
lookup_vingette.npy [new file with mode: 0644]
loop.py
sample.jpg

index b81a726ed55de9a831c1c1da6698e817e2e2b428..f24b8e54ef6d950def15e2d6db6ea1c5d8abaa9a 100644 (file)
Binary files a/__pycache__/camera.cpython-311.pyc and b/__pycache__/camera.cpython-311.pyc differ
index 155cc804c0f9366e6919180884a150a8427b9ee2..9c660ef2d9b20dfb9f47494e8710523b08fc7b3b 100644 (file)
--- a/camera.py
+++ b/camera.py
@@ -5,12 +5,12 @@ import threading
 
 class VideoCapture:
        def __init__(self, device_id):
-               cv.CAP_GSTREAMER
-               self.camera = cv.VideoCapture(device_id)
+
+               self.camera = cv.VideoCapture(device_id + cv.CAP_GSTREAMER)
                self.camera.set(cv.CAP_PROP_FRAME_WIDTH, 1920.0)
                self.camera.set(cv.CAP_PROP_FRAME_HEIGHT, 1080.0)
 
-               self.queue = Queue.Queue()
+               self.queue = queue.Queue()
                read_thread = threading.Thread(target=self.reader)
                read_thread.daemon = True
                read_thread.start()
@@ -18,7 +18,7 @@ class VideoCapture:
        # read frames as soon as they are available, keeping only most recent one
        def reader(self):
                while True:
-                       ret, frame = self.cap.read()
+                       ret, frame = self.camera.read()
                        if not ret:
                                break
                        if not self.queue.empty():
@@ -28,8 +28,11 @@ class VideoCapture:
                                        pass
                        self.queue.put(frame)
 
+       def set(self, a, b):
+               return
+
        def read(self):
-               return self.queue.get()
+               return None, self.queue.get()
 
 class camera():
        def __init__(
@@ -49,11 +52,9 @@ class camera():
                self.show_debug = debug
                self.dummy = dummy
 
-               cv.CAP_GSTREAMER
-
-               self.camera = cv.VideoCapture(device_id)
+               self.camera = VideoCapture(device_id)
 
-               self.camera.set(cv.CAP_PROP_BUFFERSIZE, 1)
+               self.camera.set(cv.CAP_PROP_BUFFERSIZE, 38)
                self.camera.set(cv.CAP_PROP_FRAME_WIDTH, 1920.0)
                self.camera.set(cv.CAP_PROP_FRAME_HEIGHT, 1080.0)
 
@@ -88,7 +89,7 @@ class camera():
 
                cv.imshow("display", calibration_image)
                cv.waitKey(0)
-               capture = self.camera.read()
+               _, capture = self.camera.read()
 
                # detect SIFT keypoints
                sift = cv.SIFT_create()
@@ -142,16 +143,16 @@ class camera():
 
                        for y in range(0, self.window_height, vingette_compression):
                                for x in range(0, self.window_size, vingette_compression):
-                                       self.lookup_vingette[v, y, x] = capture[y, x, 2] - v
+                                       self.lookup_vingette[v // vingette_compression, y // vingette_compression, x // vingette_compression] = capture[y, x, 2] - v
 
                color_compression = 90
 
-               self.lookup_color = np.array((
+               self.lookup_color = np.zeros((
                        180 // color_compression + 1,
                        255 // color_compression + 1,
                        255 // color_compression + 1,
                        3
-               ))
+               ), dtype=np.uint8)
 
                for h in range(0, 180, color_compression):
                        for s in range(0, 255, color_compression):
@@ -203,16 +204,14 @@ class camera():
                        image = self.last_display
 
                else:
-                       image = self.camera.read()
+                       _, image = self.camera.read()
                        self.last_capture = image
                        if self.homography is not None:
                                image = cv.warpPerspective(image, self.homography, self.display_size)
                                image = cv.resize(image, (self.window_size, self.window_height))
 
                if self.lookup_vingette is not None and self.lookup_color is not None:
-                       for row in image:
-                               for pixel in row:
-                                       pixel = self.lookup[pixel[0], pixel[1], pixel[2]]
+                       pass
 
                self.last_recovered = image
 
diff --git a/lookup_color.npy b/lookup_color.npy
new file mode 100644 (file)
index 0000000..7f04a4e
Binary files /dev/null and b/lookup_color.npy differ
diff --git a/lookup_vingette.npy b/lookup_vingette.npy
new file mode 100644 (file)
index 0000000..4f36d72
Binary files /dev/null and b/lookup_vingette.npy differ
diff --git a/loop.py b/loop.py
index 34bc909dae0d2254cd37d220192ba20484a98757..b61302d28f53b36b14619d90dd33691ce7881ebe 100644 (file)
--- a/loop.py
+++ b/loop.py
@@ -23,15 +23,15 @@ notes:
 """
 
 sample_rate, data = wavfile.read("/home/will/Downloads/Adducci - Around the Horn.wav")
-# data = data[...,0]
+#data = data[...,0]
 
-new_rate = 22050.
+new_rate = 11025.
 sample_count = round(len(data) * new_rate / sample_rate)
 data = sps.resample(data, sample_count)
 sample_rate = int(new_rate)
 
-window_size = 176
-window_height = 99
+window_size = 192
+window_height = 108
 
 hop_size = window_size // 2
 camera = camera(
@@ -39,14 +39,14 @@ camera = camera(
        window_height,
        (1840, 1000),
        device_id=2,
-       debug=False,
-       dummy=True
+       debug=True,
+       dummy=False
 )
 camera.calibrate()
-camera.get_lookup()
 
-print(camera.lookup_vingette)
-print(camera.lookup_color)
+#camera.get_lookup()
+#print(camera.lookup_vingette)
+#print(camera.lookup_color)
 
 transform = fft(window_size, hop_size)
 
@@ -113,7 +113,7 @@ try:
                if segment_index == segment_count: segment_index = 0
 
                slept = 0
-               while len(audio) > 2 * segment_samples:
+               while len(audio) > 3 * segment_samples:
                        time.sleep(0.01)
                        slept += 1
                print(f"slept {slept} times")
index b9e3d341f135101c34f2c2411a83d1220db39740..9d62489aaa72d01de5eb3c230aba186ea1447573 100644 (file)
Binary files a/sample.jpg and b/sample.jpg differ