Erkennung von Braille-Punkten auf Bildern mithilfe von OpenCVPython

Python-Programme
Guest
 Erkennung von Braille-Punkten auf Bildern mithilfe von OpenCV

Post by Guest »

Für ein Projekt möchte ich Braillepunkte auf einer Platte erkennen. Ich mache ein Bild, auf dem ich dank der Funktion connectedComponentsWithStats meine Erkennung durchführe. Trotz meiner Versuche kann ich nie einen Schwellenwert ermitteln, bei dem alle Punkte und nur diese erkannt werden. Ich habe das gleiche Problem, wenn ich versuche, die Kreiserkennung zu verwenden. Ich versuche auf Anraten eines Lehrers, den Vorlagenabgleich zu verwenden, habe aber auch Probleme mit meiner Erkennung, da der einzige Faktor, der sie beeinflusst, der Schwellenwert ist.

Code: Select all

import matplotlib.pyplot as plt

img1 = cv.imread(r"traitement\prod.png")

plt.figure(figsize=(40,40))
plt.subplot(3,1,1)

gray_img = cv.cvtColor(img1, cv.COLOR_BGR2GRAY)

test = cv.adaptiveThreshold(gray_img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 11, 6)

_, _, boxes, _ = cv.connectedComponentsWithStats(test)

boxes = boxes[1:]
filtered_boxes = []
for x,y,w,h,pixels in boxes:
if pixels < 1000 and h < 35 and w < 35 and h > 14 and w > 14 and x > 15 and y > 15:
filtered_boxes.append((x,y,w,h))

for x,y,w,h in filtered_boxes:
W = int(w)/2
H = int(h)/2
#print(w)
cv.circle(img1,(x+int(W),y+int(H)),2,(0,255,0),20)

cv.imwrite("gray.png",gray_img)
cv.imwrite("test.png",test)

plt.imshow(test)

plt.subplot(3,1,2)
plt.imshow(img1)

Code: Select all

import cv2 as cv
import numpy as np
from imutils.object_detection import non_max_suppression
import matplotlib.pyplot as plt

img = cv.imread('traitement/prod.png')
temp_gray = cv.imread('dot.png',0)

W, H = temp.shape[:2]
thresh = 0.6

img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
match = cv.matchTemplate(image=img_gray, templ=temp_gray, method=cv.TM_CCOEFF_NORMED)

(y_points, x_points) = np.where(match >= thresh)

boxes = list()

for (x, y) in zip(x_points, y_points):

# update our list of rectangles
boxes.append((x, y, x + W, y + H))

boxes = non_max_suppression(np.array(boxes))

# loop over the final bounding boxes
for (x1, y1, x2, y2) in boxes:
cv.circle(img,(x1+int(W/2),y1+int(H/2)),2,(255,0,0),15)

plt.figure(figsize=(40,40))
plt.subplot(3,1,1)
plt.imshow(img)

Bild mit adaptivem Schwellenwert:
Image

Bild mit Vorlagenerkennung:
[img]https:// i.sstatic.net/TYuvR.jpg[/img]

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post