Dies ist mein erstes Projekt in Python (3.5.1) und OpenCV (3), also tut mir leid für meine Fehler. Ich habe ein paar Bilder wie diese: https://s12.postimg.org/ox8gw5l8d/gado.jpgZählen Sie die Anzahl der Objekte OpenCV - Python
Ich muss zählen, wie viele weiße Objekte auf diesem Bild hat. Ich habe versucht, SimpleBlobDetector, aber ich habe nicht so gearbeitet, wie ich es erwartet hatte.
# Standard imports
import cv2
import numpy as np;
# Read image
im = cv2.imread("C:/opencvTests/cattle.jpg", cv2.IMREAD_GRAYSCALE)
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
#filter by color
params.filterByColor = True
params.blobColor = 255
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.87
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.08
# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypoints = detector.detect(im)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imwrite("C:/opencvTests/blobSave.jpg",im_with_keypoints)
print("Total of objects")
print(len(keypoints))
Jede Hilfe wäre wirklich zu schätzen! Vielen Dank im Voraus
Vielen Dank für das Teilen Sie mir Ihr Wissen Herr Arjun. –
@EcheverryaAvila Ich bin froh, dass es dir geholfen hat. Alles Gute..! – Arjun