本文整理匯總了Python中cv2.SimpleBlobDetector_create方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.SimpleBlobDetector_create方法的具體用法?Python cv2.SimpleBlobDetector_create怎麽用?Python cv2.SimpleBlobDetector_create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.SimpleBlobDetector_create方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _find_triangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import SimpleBlobDetector_create [as 別名]
def _find_triangle(image, blob_params=None):
"""Finds the three dots for calibration in the image
(of a 30 60 90 degree triangle)
Parameters
----------
image :
return: the three triangle points
blob_params :
(Default value = None)
Returns
-------
type
the three triangle points
"""
if blob_params is None:
blobdet = cv2.SimpleBlobDetector_create()
else:
blobdet = cv2.SimpleBlobDetector_create(blob_params)
# TODO check if blob detection is robust
scaled_im = 255 - (image.astype(np.float32) * 255 / np.max(image)).astype(
np.uint8
)
keypoints = blobdet.detect(scaled_im)
if len(keypoints) != 3:
raise CalibrationException("3 points for calibration not found")
kps = np.array([k.pt for k in keypoints])
# Find the angles between the points
# and return the points sorted by the angles
return kps[np.argsort(CircleCalibrator._find_angles(kps)), :]
示例2: init_blob_detector
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import SimpleBlobDetector_create [as 別名]
def init_blob_detector():
params = cv2.SimpleBlobDetector_Params()
params.minThreshold = 1
params.maxThreshold = 255
params.filterByArea = True
params.minArea = 1
params.filterByCircularity = False
params.filterByConvexity = False
params.filterByInertia = False
#detector = cv2.SimpleBlobDetector(params)
detector = cv2.SimpleBlobDetector_create(params)
return detector
示例3: add_blobs
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import SimpleBlobDetector_create [as 別名]
def add_blobs(crop_frame):
frame=cv2.GaussianBlur(crop_frame, (3, 3), 0)
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of green color in HSV
lower_green = np.array([70,50,50])
upper_green = np.array([85,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_green, upper_green)
mask = cv2.erode(mask, None, iterations=1)
mask = cv2.dilate(mask, None, iterations=1)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
reversemask=255-mask
keypoints = detector.detect(reversemask)
if keypoints:
print "found blobs"
if len(keypoints) > 4:
keypoints.sort(key=(lambda s: s.size))
keypoints=keypoints[0:3]
# 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(frame, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
else:
print "no blobs"
im_with_keypoints=crop_frame
return im_with_keypoints #, max_blob_dist, blob_center, keypoint_in_orders
示例4: init_blob_detector
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import SimpleBlobDetector_create [as 別名]
def init_blob_detector():
params = cv2.SimpleBlobDetector_Params()
params.minThreshold = 1
params.maxThreshold = 255
params.filterByArea = True
params.minArea = 1
params.filterByCircularity = False
params.filterByConvexity = False
params.filterByInertia = False
# detector = cv2.SimpleBlobDetector(params)
detector = cv2.SimpleBlobDetector_create(params)
return detector
示例5: analyse_frame
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import SimpleBlobDetector_create [as 別名]
def analyse_frame(self,frame):
balloon_found = False
balloon_x = 0
balloon_y = 0
balloon_radius = 0
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Threshold the HSV image
mask = cv2.inRange(hsv, self.filter_low, self.filter_high)
# Erode
erode_kernel = numpy.ones((3,3),numpy.uint8);
eroded_img = cv2.erode(mask,erode_kernel,iterations = 1)
# dilate
dilate_kernel = numpy.ones((10,10),numpy.uint8);
dilate_img = cv2.dilate(eroded_img,dilate_kernel,iterations = 1)
# blog detector
blob_params = cv2.SimpleBlobDetector_Params()
blob_params.minDistBetweenBlobs = 50
blob_params.filterByInertia = False
blob_params.filterByConvexity = False
blob_params.filterByColor = True
blob_params.blobColor = 255
blob_params.filterByCircularity = False
blob_params.filterByArea = False
#blob_params.minArea = 20
#blob_params.maxArea = 500
blob_detector = cv2.SimpleBlobDetector_create(blob_params)
keypts = blob_detector.detect(dilate_img)
# draw centers of all keypoints in new image
#blob_img = cv2.drawKeypoints(frame, keypts, color=(0,255,0), flags=0)
# find largest blob
if len(keypts) > 0:
kp_max = keypts[0]
for kp in keypts:
if kp.size > kp_max.size:
kp_max = kp
# draw circle around the largest blob
cv2.circle(frame,(int(kp_max.pt[0]),int(kp_max.pt[1])),int(kp_max.size),(0,255,0),2)
# set the balloon location
balloon_found = True
balloon_x = kp_max.pt[0]
balloon_y = kp_max.pt[1]
balloon_radius = kp_max.size
# return results
return balloon_found, balloon_x, balloon_y, balloon_radius
# add_artificial_horizon - adds artificial horizon to an image using the vehicle's attitude