Dieser Teil identifiziert die Kleckse im Bild (kleiner, niedrige Qualität). Bilder funktionieren momentan nicht)
Code: Select all
import cv2
import numpy as np
from sklearn.cluster import KMeans
# Load the image
image_path = "braille.jpg"
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Set up SimpleBlobDetector
params = cv2.SimpleBlobDetector_Params()
# Filter by area (size of the blob)
params.filterByArea = True
params.minArea = 100 # Adjust based on dot size
params.maxArea = 1000
# Filter by circularity
params.filterByCircularity = True
params.minCircularity = 0.9 # Adjust for shape of the dots
# Filter by convexity
params.filterByConvexity = False
params.minConvexity = 0.7
# Filter by inertia (roundness)
params.filterByInertia = True
params.minInertiaRatio = 0.95
# Create a detector with the parameters
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs
keypoints = detector.detect(image)
# Draw detected blobs as red circles
output_image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
output_image = cv2.drawKeypoints(output_image, keypoints, np.array([]),
(0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
print("output image")
cv2.imshow("outputimage",output_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(f"Number of blobs detected: {len(keypoints)}")
Code: Select all
#convert image into graph
import matplotlib.pyplot as plt
import numpy
blob_coords = np.array([kp.pt for kp in keypoints]) #coords of blob
rounded_coords = np.round(blob_coords).astype(int) #rounded coords
x_coords = rounded_coords[:, 0]
y_coords = rounded_coords[:, 1]
# PROXIMITY BASED GROUPING
# IF X DISTANCE IS LESS THAN MIN DISTANCE
# IF Y DISTANCE IS LESS THAN MIN DISTANCE
# STORE X AND Y COORDINATES
# Calculate smallest x and y differences (trying for proximity based)
minx = 10000
miny = 10000
for i in x_coords:
for j in x_coords:
if abs(i - j)