Solrikk / PicTrace

🔎 PicTrace is a highly efficient image matching platform that leverages computer vision using OpenCV, deep learning with TensorFlow and the ResNet50 model, asynchronous processing with aiohttp, and the FastAPI web framework for rapid and accurate image search.
https://pictrace.tech
Apache License 2.0
10 stars 2 forks source link

How to create a database #4

Open gaojulong opened 3 weeks ago

gaojulong commented 3 weeks ago

How to create a database?

Solrikk commented 3 weeks ago

Hi there! Currently, the database is in JSON format, containing links to photos. However, I am working on a more user-friendly database solution with detailed instructions that will be available soon

Brief Instruction on Using the Database:

Additionally, you can easily modify the file to implement your own database solution. Here is an example of how might look if you want to make adjustments:

import sqlite3

def init_db():
    conn = sqlite3.connect('images.db')
    cursor = conn.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS images (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            image_hash TEXT NOT NULL,
            file_path TEXT NOT NULL
        )
    ''')
    conn.commit()
    conn.close()

def add_image_to_db(file_path, image_hash):
    conn = sqlite3.connect('images.db')
    cursor = conn.cursor()
    cursor.execute('INSERT INTO images (image_hash, file_path) VALUES (?, ?)', (image_hash, file_path))
    conn.commit()
    conn.close()

def load_db():
    conn = sqlite3.connect('images.db')
    cursor = conn.cursor()
    cursor.execute('SELECT image_hash, file_path FROM images')
    db_data = [{"hash": row[0], "path": row[1]} for row in cursor.fetchall()]
    conn.close()
    return db_data

def save_db(data):
    conn = sqlite3.connect('images.db')
    cursor = conn.cursor()
    cursor.executemany('INSERT INTO images (image_hash, file_path) VALUES (?, ?)', [(entry["hash"], entry["path"]) for entry in data])
    conn.commit()
    conn.close()

I hope this helps! If you have any questions or need further assistance, feel free to ask

Solrikk commented 3 weeks ago

Hi there!

I hope you're doing well. I just wanted to inform you that I have switched from using a JSON format for the database to using S3 storage for handling image uploads and retrievals. This new solution improves efficiency and scalability.

Brief Instruction on Using the New S3 Database:

I hope this helps clarify the new storage solution!

image