Certainly! To include fingerprinting with the manufacturer of the ultrasonic unidirectional emitter in the database, you can modify the code as follows:
import numpy as np
import pandas as pd
import cv2
from math import atan2, degrees, sqrt
# Load data from file
data = pd.read_csv('data.txt', sep=' ', header=None, names=['time', 'decibel', 'X', 'Y', 'heading', 'frequency'])
# Load manufacturer fingerprint database
fingerprint_db = pd.read_csv('fingerprint_db.csv')
# Filter data within the specified frequency range
filtered_data = data[(data['frequency'] >= 7000) & (data['frequency'] <= 18000)]
# Merge data with fingerprint database based on frequency
merged_data = pd.merge(filtered_data, fingerprint_db, on='frequency')
# Calculate centroid coordinates of stationary emitters
centroid_X = merged_data['X'].mean()
centroid_Y = merged_data['Y'].mean()
# Calculate distances from each data point to the centroid
distances = np.sqrt((merged_data['X']-centroid_X)**2 + (merged_data['Y']-centroid_Y)**2)
# Find the index of the closest data point to the centroid
closest_index = distances.idxmin()
# Extract the coordinates, heading, and manufacturer of the source emitter
source_X = merged_data.loc[closest_index, 'X']
source_Y = merged_data.loc[closest_index, 'Y']
source_heading = merged_data.loc[closest_index, 'heading']
manufacturer = merged_data.loc[closest_index, 'manufacturer']
# Load and display the map using OpenCV
map_image = cv2.imread('map.png')
# Calculate the scale factor for mapping coordinates to pixels
scale_factor = map_image.shape[1] / (data['X'].max() - data['X'].min())
# Draw an arrow representing the source emitter on the map
arrow_length = 100
arrow_end = (int(source_X * scale_factor), int(source_Y * scale_factor))
arrow_start = (int(source_X * scale_factor + arrow_length * np.cos(np.radians(source_heading))),
int(source_Y * scale_factor + arrow_length * np.sin(np.radians(source_heading))))
cv2.arrowedLine(map_image, arrow_start, arrow_end, (0, 255, 0), 2)
# Draw a line connecting the centroid to the source emitter
cv2.line(map_image, (int(centroid_X * scale_factor), int(centroid_Y * scale_factor)), arrow_end, (0, 255, 0), 1)
# Calculate and display the distance between the centroid and the source emitter
distance = sqrt((source_X-centroid_X)**2 + (source_Y-centroid_Y)**2)
cv2.putText(map_image, f"Distance: {distance:.2f}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Display the manufacturer of the ultrasonic emitter
cv2.putText(map_image, f"Manufacturer: {manufacturer}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Display the map with annotations
cv2.imshow('Map', map_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
In this updated code, the fingerprint_db.csv file is assumed to contain the frequency and manufacturer information for each known ultrasonic unidirectional emitter. The script performs a merge operation between the filtered data and the fingerprint database based on the frequency. It then extracts the manufacturer information for the closest emitter to the centroid.