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. PicTrace allows users to upload images directly or provide URLs, quickly scanning a vast database to find similar images. Asynchronous processing ensures smooth and fast visual search, enhancing the user experience.
PicTrace is a powerful image tracing and comparison tool designed to streamline your development process. Follow these steps to set up your environment and launch the application successfully.
To work with PicTrace, ensure you have the following components installed:
Operating System | Commands for Setup and Launch |
---|---|
Linux | bash sudo git clone https://github.com/Solrikk/PicTrace.git cd PicTrace sudo pip install poetry sudo poetry install sudo poetry run python3 main.py |
macOS | bash sudo git clone https://github.com/Solrikk/PicTrace.git cd PicTrace sudo pip install poetry sudo poetry install sudo poetry run python3 main.py |
Windows | Open Command Prompt as Administrator and run: bash git clone https://github.com/Solrikk/PicTrace.git cd PicTrace pip install poetry poetry install poetry run python main.py |
Curious to see how PicTrace works in real-time?
Explore my online demo and witness the capabilities of my image matching platform.
Online Demo - Give it a try and see for yourself!
Supports Multiple Technologies πΌ
Python with these powerful libraries:
FastAPI:
Ideal for web application creation and handling HTTP requests, FastAPI is known for its high performance and support for asynchronous operations. Detailsaiohttp:
Perfect for handling asynchronous HTTP requests, such as downloading images by URL, making your app faster and more efficient. DetailsOpenCV (cv2):
A robust computer vision library used for advanced image processing, including loading, resizing, and comparing images, making it a critical component for your image-related tasks. Detailsnumpy:
A versatile library for working with multi-dimensional arrays, often used alongside OpenCV for efficient image processing. More Infoscikit-image:
Particularly, the structural_similarity
(SSIM) function from this library is employed to compare the similarity of images, enhancing your application's accuracy in image matching. Detailshashlib:
Utilized for generating unique hashes for each image, ensuring every image can be uniquely identified and efficiently managed. More InfoSupports Multiple Indexes ποΈ
Image Hashing:
Generating unique hashes for images to ensure unique identification and efficient management.Feature Extraction with ResNet50:
Utilizes the ResNet50 model for extracting robust feature representations from images.Cosine Similarity:
Measuring similarity between images using cosine similarity on feature vectors extracted from the images.For complex images with many details and possible presence of noise or distortions, even similarity at the level of 20% and above can indicate the presence of significant common features. In such cases, a low percentage of similarity may be expected due to the complexity of the task and the limitations of the algorithm. | Image 1 vs Image 2 | Similar | Image |
---|---|---|---|
27,12% | |||
25,44% | |||
44,16% |
(code with comments)
async def find_similar_images(file_path):
# Load the data from the database, which contains information about images.
db_data = load_db()
# Read the target image from the given file path.
target_image = cv2.imread(file_path)
# Extract features from the target image using a pre-trained model.
target_features = extract_features(target_image)
# Create an aiohttp asynchronous session for handling HTTP requests.
async with aiohttp.ClientSession() as session:
# Create asynchronous tasks for the compare_images function for each image in the database.
tasks = [
compare_images(session, entry, target_features) for entry in db_data
if "url" in entry # Only perform comparisons for entries that contain an image URL.
]
# Wait for all tasks to complete and gather the results.
results = await asyncio.gather(*tasks)
# Filter the results, keeping only those with a similarity score greater than 0.
valid_results = filter(lambda x: x[0] > 0, results)
# Sort the filtered results by similarity score in descending order and take the top 5.
sorted_results = sorted(valid_results, key=lambda x: x[0], reverse=True)[:5]
# Create a list to store the URLs of the similar images.
similar_images = []
for result in sorted_results:
if result[1]:
similar_images.append(result[1])
# Return the list of URLs of the similar images.
return similar_images
OpenCV is a powerful computer vision library that provides tools for image and video processing. It is widely used in fields related to machine vision, image recognition, video analysis, and more. The library includes a wide range of algorithms for image analysis, such as object detection, face recognition, motion tracking, video manipulation, and more.
Key features of OpenCV include:
The ResNet50 (Residual Network) model is one of the most popular and powerful deep learning architectures for image classification and feature extraction tasks. Your neural network model ResNet50 provides the following advantages:
Together, OpenCV and ResNet50 can be used to create powerful computer vision applications that can analyze visual data and perform complex tasks, such as automatic object recognition and image classification.
The ORB method, used in computer vision, is particularly popular for tasks related to object recognition, image matching, and tracking. This method focuses on quickly finding key points on images and describing them in a way that allows for efficient comparison.
Oriented FAST (Features from Accelerated Segment Test) π: This component is responsible for detecting points of interest (or key points) on the image. It quickly identifies corners or edges that stand out in comparison to their surrounding areas. This way, significant or unique sections of the image can be identified.
Rotated BRIEF (Binary Robust Independent Elementary Features) π: After key points have been found, it is necessary to create a description for each to allow comparison with key points from another image. BRIEF generates a brief binary description of the points but lacks resistance to image rotation. This is where the "rotated" part comes in - ORB adds the ability to stably describe points even when images are rotated.
Combining these two approaches, ORB provides a fast and efficient way of matching images despite changes in viewing angle, scale, or lighting.
PicTrace uses both SSIM and ORB methods to find images that are similar to an uploaded image. Here's a simplified explanation of how each method works in the context of your application and contributes to finding similar images:
Together, the SSIM and ORB methods provide a robust and accurate way to find and compare images that are similar to the uploaded image.