vertopal.com_tp4
vertopal.com_tp4
Parameters:
image_path (str): Path to the image file.
Returns:
tuple: Keypoints and descriptors extracted by ORB.
"""
# Read the image using Pillow and convert it to grayscale
img = Image.open(image_path).convert("L")
img_np = np.array(img) # Convert the grayscale image to a NumPy
array
Parameters:
desc1, desc2 (np.array): Descriptors from two images.
Returns:
int: Number of good matches based on Lowe's ratio test.
"""
# Initialize BFMatcher with Hamming distance (suitable for binary
descriptors like ORB)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
Parameters:
query_image (str): Path to the query image.
folder (str): Path to the folder containing images.
Returns:
list: A sorted list of tuples (filename, match_count) in
descending order of match count.
"""
# Extract ORB features from the query image
query_kp, query_desc = extract_orb_features(query_image)
results = [] # List to store match results
# Iterate through each image in the folder
for filename in os.listdir(folder):
# Process only image files with specific extensions
if filename.endswith(('.jpg', '.jpeg', '.png')):
image_path = os.path.join(folder, filename) # Full path
to the image
try:
# Extract ORB features from the current image
_, desc = extract_orb_features(image_path)
if desc is not None: # Ensure descriptors are valid
# Match ORB features between the query image and
the current image
match_count = match_orb_features(query_desc, desc)
# Append the result (filename and match count) to
the results list
results.append((filename, match_count))
except Exception as e:
print(f"Error processing {image_path}: {e}")
Parameters:
query_image_path (str): Path to the query image.
folder_path (str): Path to the folder containing images.
results (list): A list of tuples (filename, match_count) for
similar images.
"""
fig, axes = plt.subplots(1, len(results), figsize=(15, 5)) #
Create a subplot
plt.tight_layout()
plt.show()
# Query and folder paths
query_image_path = r"Base d'images N°10/6610.jpg" # Path to the query
image
folder_path = r"Base d'images N°10" # Path to the folder containing
images
return hog_features
plt.tight_layout()
plt.show()
# Query and folder paths
query_image_path = r"Base d'images N°10/6610.jpg"
folder_path = r"Base d'images N°10"
All in one
# Find similar images considering scale differences
print("sift results")
# Find similar images
try:
sift_results = find_similar_sift(query_image_path, folder_path)
top_results = sift_results[:15] # Show top 10 results
# Display the results
display_results(query_image_path, folder_path, top_results)
except Exception as e:
print(f"Error: {e}")
sift results
harris results
hog results
HOG Représentation des formes | Partielle (aux petits décalages) | Excellente pour la détection
d’objets | Sensible aux variations d’échelle