Ich arbeite an einem OMR -Blattverarbeitungssystem, bei dem Benutzer in vier Spalten (A, B, C, D) Antworten sprudeln. Mein Ziel ist es, jede einzelne Blase in jeder Spalte zu erkennen. /> Für die Spalten 1 und 4 kann ich die Blasen korrekt erkennen. < /li>
Für die Spalten 2 und 3 schlägt mein Algorithmus fehl einzelner Blasen. Vc5jewlt.png "/>
Mein Code für dasselbe ist 0:
# Sort contours by area in descending order
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
# Loop over sorted contours
for c in cnts:
# Approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# If the approximated contour has four points, we assume it's the document
if len(approx) == 4 and count_counter < 6:
if count_counter == counter_needed:
print(count_counter)
docCnt = approx
break
count_counter += 1
paper = four_point_transform(image, docCnt.reshape(4, 2))
warped = four_point_transform(gray, docCnt.reshape(4, 2))
# apply Otsu's thresholding method to binarize the warped piece of paper
thresh = cv2.threshold(warped, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
show_image("Threshold Image 2", thresh)
contour_image = cv2.cvtColor(thresh, cv2.COLOR_GRAY2BGR) # Convert to BGR for colored visualization
# Apply thresholding (assuming `thresh` is already computed)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# print(cnts)
for idx, c in enumerate(cnts):
color = (np.random.randint(0, 255), np.random.randint(0, 255), np.random.randint(0, 255))
cv2.drawContours(contour_image, [c], -1, color, 2) # Random color for each contour
# Get bounding box for labeling
x, y, w, h = cv2.boundingRect(c)
# print(x, y, w, h)
# Add index number to each contour
cv2.putText(contour_image, f"{idx}", (x, y - 5),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
# Display the image with all contours
show_image("Counter 1", contour_image)
[/code]
Ausgabe bei der Erkennung der Blase des OMR -Blattes ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post