本文整理汇总了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