This code aims to record two signals, calculate the tdoa between the sources and use a…
- User
This code aims to record two signals, calculate the tdoa between the sources and use a heat map. However, we are using two mics and I am not sure how to adequately configure the position of the mics related to the camera. import sounddevice as sd import numpy as np import cv2 import time from scipy.signal import correlate from queue import Queue import threading import matplotlib.pyplot as plt
Parameters
SAMPLE_RATE = 44100 # Sampling rate in Hz BUFFER_DURATION = 0.05 # Duration of each audio buffer in seconds (e.g., 50 ms) CHANNELS = [1] # We'll use one channel per device DEVICE_IDS = [1,2] # Replace with actual device IDs
Define microphone positions (in meters)
For example, microphones are 0.5 meters apart along x-axis
mic_positions = [(0.0, 0.0), (0.1, 0.0)]
Initialize queues for audio data
audio_queue1 = Queue() audio_queue2 = Queue()
Initialize the queue to communicate position data
position_queue = Queue()
Initialize video capture
video_capture = cv2.VideoCapture(0) # Adjust the index if multiple cameras
if not video_capture.isOpened(): print("Error: Could not open video device") exit(1)
def create_heatmap(frame, position, delta_d, mic_positions): # Create an empty heatmap heatmap = np.zeros((frame.shape[0], frame.shape[1]), dtype=np.float32)
code# Map the estimated position to pixel coordinates # Assuming the frame represents the area between microphones x_pixels = np.interp(position[0], [mic_positions[0][0], mic_positions[1][0]], [0, frame.shape[1]]) y_pixels = frame.shape[0] / 2 # For simplicity, assuming y is centered # Draw a circle representing the source position cv2.circle(heatmap, (int(x_pixels), int(y_pixels)), radius=50, color=1.0, thickness=-1) # Normalize heatmap to range [0, 255] heatmap = cv2.normalize(heatmap, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) heatmap = heatmap.astype(np.uint8) # Apply a color map heatmap_color = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) # Overlay the heatmap onto the frame overlay = cv2.addWeighted(frame, 0.7, heatmap_color, 0.3, 0) return overlay - Assistant