From: will Date: Mon, 5 Aug 2024 18:01:19 +0000 (+0100) Subject: - Added VideoCapture thread class to continuously capture frames X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=3238cbb5df8d51f77749575f6b4024a339fbde69;p=audio-over-stft - Added VideoCapture thread class to continuously capture frames - Built vingette and color lookup table generator - Tweaks to the looper file (loop.py) --- diff --git a/__pycache__/camera.cpython-311.pyc b/__pycache__/camera.cpython-311.pyc index b81a726..f24b8e5 100644 Binary files a/__pycache__/camera.cpython-311.pyc and b/__pycache__/camera.cpython-311.pyc differ diff --git a/camera.py b/camera.py index 155cc80..9c660ef 100644 --- 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 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 index 0000000..4f36d72 Binary files /dev/null and b/lookup_vingette.npy differ diff --git a/loop.py b/loop.py index 34bc909..b61302d 100644 --- 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") diff --git a/sample.jpg b/sample.jpg index b9e3d34..9d62489 100644 Binary files a/sample.jpg and b/sample.jpg differ