Today I added a MySQL database, and updated code so that the images and accompanying species ID are sent to the database! First we needed to fetch just the species name from the dict which contains all the classification information (e.g. probability etc.): species_name = species["predicted_class"]
CREATE DATABASE whosthatbird;
USE whosthatbird;
CREATE TABLE bird_sightings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
image_path VARCHAR(255) NOT NULL,
species VARCHAR(100) NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
Then, I added the code to insert to the MySQL table in the annotate_photo module (for now):
#let's put the code for insert to MySQL table here
timestamp = datetime.now()
#connect to DB
conn = mysql.connector.connect(
host="localhost",
user="user",
password="password",
database="whosthatbird"
)
cursor = conn.cursor()
cursor.execute(
"INSERT INTO bird_sightings (image_path, species, timestamp) VALUES (%s, %s, %s)",
(image_path, species_name, timestamp)
)
conn.commit()
cursor.close()
conn.close()
Neil K. Sheridan
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.