From: will Date: Tue, 3 Sep 2024 19:17:51 +0000 (+0100) Subject: Various small changes X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=d385809d307735c6dfa7631279ee58858c5ba6c2;p=audio-over-stft Various small changes + fixed .gitignore - removed color correction - removed other depricated features - removed .wav file --- diff --git a/.gitignore b/.gitignore index 70e819d..0d86721 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.npy *.jpg *.wav -*.pyc -./__pycache__ +__pycache__/ diff --git a/camera.py b/camera.py index 325a2d2..4dc634f 100644 --- a/camera.py +++ b/camera.py @@ -45,24 +45,16 @@ class camera(): window_height: int, display_size: tuple, device_id: int = 0, - brightness: float = 1., - contrast: float = 0., - temperature: float = 0., - tint: float = 0., debug: bool = True, - dummy: bool = False, - use_lookup: bool = False, - use_files: bool = False, + dummy: bool = False ): self.window_size = window_size self.window_height = window_height self.display_size = display_size - self.match_histograms = False + self.show_debug = debug self.dummy = dummy - self.use_lookup = use_lookup - self.use_files = use_files self.camera = cv.VideoCapture(device_id, cv.CAP_V4L) @@ -72,8 +64,6 @@ class camera(): self.camera.set(cv.CAP_PROP_FRAME_HEIGHT, 1080.0) self.homography = None - self.lookup = None - self.lookup_compression = 100 self.last_display = None self.last_capture = None self.last_recovered = None @@ -122,49 +112,6 @@ class camera(): print("calibration failed") quit() - if self.use_lookup == True: - self.get_lookup() - - def get_lookup( - self - ) -> None: - - if self.use_files == True: - self.lookup = np.load("lookup.npy") - return - - lookup = None - - for (r, g, b) in [(0,0,0), (255,255,255)]: - pixel = np.array([[[b, g, r]]], dtype=np.int8) - pixel = cv.resize(pixel, self.display_size, interpolation=cv.INTER_NEAREST_EXACT) - self.display(pixel) - - for i in range(100): # silly hack - cv.waitKey(1) - recovered = self.capture() - - error = np.copy(recovered.astype(np.int16)) - error[..., 0] -= b - error[..., 1] -= g - error[..., 2] -= r - - error = np.clip(error, -50, 255) - - if lookup is None: - lookup = error - else: - lookup += error - lookup = lookup // 2 - - self.lookup = lookup - np.save("lookup.npy", lookup) - - lookup += np.min(lookup) - lookup = np.round(lookup * (255 / np.min(lookup))) - cv.imwrite("lookup.jpg", lookup) - - def display( self, image: np.ndarray @@ -172,28 +119,11 @@ class camera(): self.last_display = image image = cv.resize(image, self.display_size, interpolation=cv.INTER_NEAREST_EXACT) - image = cv.convertScaleAbs(image, alpha=self.contrast, beta=self.brightness) # contrast / brightness correction - image[...,2] + self.temperature # color correction - image[...,1] + self.tint - image[...,0] - self.temperature + image[...,0] = np.round(image[...,0] * 0.9) cv.imshow("display", image) cv.waitKey(1) - def debug( - self - ) -> None: - - if self.last_display is not None and self.last_capture is not None and self.last_recovered is not None: - height = round(self.last_capture.shape[0] / 2) - width = round((self.display_size[0] / self.display_size[1]) * height) - last_display = cv.resize(self.last_display, (width, height)) - last_recovered = cv.resize(self.last_recovered, (width, height)) - comparison = np.concatenate((last_display, last_recovered), axis=0) - debug_image = np.concatenate((self.last_capture, comparison), axis=1) - cv.imshow("debug", debug_image) - cv.waitKey(1) - def capture( self ) -> np.ndarray: @@ -209,9 +139,6 @@ class camera(): image = cv.warpPerspective(image, self.homography, self.display_size) image = cv.resize(image, (self.window_size, self.window_height)) - if type(self.lookup) == np.ndarray and self.use_lookup == True: - image = np.clip(image + self.lookup, 0, 255).astype(np.uint8) - self.last_recovered = image if self.show_debug == True: @@ -219,3 +146,21 @@ class camera(): return image + def debug( + self + ) -> None: + + if self.last_display is not None and self.last_capture is not None and self.last_recovered is not None: + + height = round(self.last_capture.shape[0] / 2) + width = round((self.display_size[0] / self.display_size[1]) * height) + + last_display = cv.resize(self.last_display, (width, height)) + last_recovered = cv.resize(self.last_recovered, (width, height)) + + comparison = np.concatenate((last_display, last_recovered), axis=0) + debug_image = np.concatenate((self.last_capture, comparison), axis=1) + + cv.imshow("debug", debug_image) + cv.waitKey(1) + diff --git a/fft.py b/fft.py index bd0d1df..c45456b 100644 --- a/fft.py +++ b/fft.py @@ -94,9 +94,9 @@ class fft(): image = cv.cvtColor(image, cv.COLOR_BGR2HSV) amplitude = image[0][...,2] angle = image[0][...,1].astype(np.float64) - hue = image[0][...,0].astype(np.float64) * (255/180) + #hue = image[0][...,0].astype(np.float64) * (255/180) - amplitude = np.mean( np.array([ amplitude, hue ]), axis=0 ).astype(np.uint8) + #amplitude = np.mean( np.array([ amplitude, hue ]), axis=0 ).astype(np.uint8) # convert amplitude back into vector length amplitude = self.log_lookup[amplitude] diff --git a/loop.py b/loop.py index ed974b8..b59d7f6 100644 --- a/loop.py +++ b/loop.py @@ -28,7 +28,7 @@ notes: sample_rate, data = wavfile.read("/home/will/Downloads/birdsong.wav") #data = data[...,0] -new_rate = 11025. +new_rate = 10_000. sample_count = round(len(data) * new_rate / sample_rate) data = sps.resample(data, sample_count) sample_rate = int(new_rate) @@ -42,14 +42,8 @@ camera = camera( window_height, (1920, 1080), device_id = 2, - brightness = 1., - contrast = 0., - temperature = 0., - tint = 0., debug = True, - dummy = False, - use_lookup = False, - use_files = False + dummy = False ) file = wave.open("out.wav", "wb") @@ -128,7 +122,7 @@ try: audio[-hop_size:] += row[:hop_size] audio = np.append(audio, row[hop_size:]) - #file.writeframes(row[hop_size:]) + file.writeframes(row[hop_size:]) segment_index += 1 if segment_index == segment_count: segment_index = 0 diff --git a/out.wav b/out.wav deleted file mode 100644 index 46a365a..0000000 Binary files a/out.wav and /dev/null differ