def blob_detection(img): # 初始化参数 params = cv2.SimpleBlobDetector_Params() params.minArea = 15 params.maxArea = 500 params.blobColor = 000 params.minCircularity = 10 params.maxCircularity = 10000 ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) # detector = cv2.SimpleBlobDetector(params) # 检测斑点 blobs = detector.detect(img) blobs_num = len(blobs) return blobs_num
def find_blobs(frame): params = cv2.SimpleBlobDetector_Params() params.filterByArea = True params.minArea = 150 params.filterByCircularity = False params.filterByConvexity = False params.filterByInertia = False detector = cv2.SimpleBlobDetector(params) keypoints = detector.detect(frame) counter = 0 for keyPoint in keypoints: counter = counter + 1 x = keyPoint.pt[0] y = keyPoint.pt[1] cv2.putText(frame,str(counter), (int(x),int(y+25)), cv2.FONT_HERSHEY_SIMPLEX, 1, 150) s = keyPoint.size #print x,y,s im_with_keypoints = cv2.drawKeypoints(frame, keypoints, np.array([]), (255,0,0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) return im_with_keypoints
def main(): camera = picamera.PiCamera() camera.capture('img.jpg') img = cv2.imread('img.jpg') original = img.copy() click_list = getXY(img) cropped = crop_img(original, click_list) display_image(cropped) lower, upper = myStats(cropped) print lower print upper f_image = color_in_image(original, [lower, upper]) detector = cv2.SimpleBlobDetector() keypoints = detector.detect(f_image) im_with_keypoints = cv2.drawKeypoints( im, keypoints, np.array([]), (255, 255, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
def deteccaoDeBlobs(img): #img= cv2.imread('untitled.png',cv2.IMREAD_GRAYSCALE) params = cv2.SimpleBlobDetector_Params() #img = cv2.bitwise_not(img) params.minDistBetweenBlobs = 10 params.filterByColor = True params.blobColor = 255 params.filterByCircularity = False params.filterByConvexity = False params.filterByInertia = False params.filterByArea = True # params.minArea = 1 # params.maxArea = 100000 # ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) keypoints = detector.detect(img) print(type(keypoints)) keypoints = list(reversed(keypoints)) #np.invert(keypoints) for i in keypoints: im_with_keypoints = cv2.drawKeypoints( img, [i], np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) print("################") print(i.class_id) print(i.pt) objectCentroid = i.pt print("################") break black = np.zeros((540, 960, 3)) #print(im_with_keypoints.size) #im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.imshow("Keypoints", im_with_keypoints) cv2.waitKey(0)
def create_blob_detector(roi_size=(128, 128), blob_min_area=3, blob_min_int=.5, blob_max_int=.95, blob_th_step=10): params = cv2.SimpleBlobDetector_Params() params.filterByArea = True params.minArea = blob_min_area params.maxArea = roi_size[0]*roi_size[1] params.filterByCircularity = False params.filterByColor = False params.filterByConvexity = False params.filterByInertia = False # blob detection only works with "uint8" images. params.minThreshold = int(blob_min_int*255) params.maxThreshold = int(blob_max_int*255) params.thresholdStep = blob_th_step ver = (cv2.__version__).split(".") if int(ver[0]) < 3: return cv2.SimpleBlobDetector(params) else: return cv2.SimpleBlobDetector_create(params)
def getStarBlobs(im): im = cv2.erode(im, np.ones((2, 2))) height, width = im.shape[:2] area = height * width # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Change thresholds params.minThreshold = cv2.getTrackbarPos('minThr', 'image') params.maxThreshold = cv2.getTrackbarPos('maxThr', 'image') # Filter by Area. params.filterByArea = True #10000 #500 params.minArea = area / (cv2.getTrackbarPos('minAre', 'image') + 1) params.maxArea = area / (cv2.getTrackbarPos('maxAre', 'image') + 1) # Filter by Circularity params.filterByCircularity = True params.minCircularity = cv2.getTrackbarPos('minCir', 'image') params.maxCircularity = cv2.getTrackbarPos('maxCir', 'image') # Filter by Convexity params.filterByConvexity = False params.minConvexity = cv2.getTrackbarPos('minCon', 'image') params.maxConvexity = cv2.getTrackbarPos('maxCon', 'image') # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = cv2.getTrackbarPos('minIne', 'image') ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) keypoints = detector.detect(im) print("detected") return keypoints #,im
def countcluster(picture): im = cv2.cvtColor(picture, cv2.COLOR_RGB2GRAY) kernel = np.ones((3, 5), np.uint8) im = cv2.erode(im, kernel, iterations=2) # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # filter by area params.filterByArea = True params.minArea = 2 # filter by color params.filterByColor = True params.blobColor = 255 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.001 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = .001 # 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) #dummy #im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0, 0, 255), # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Show keypoints #cv2.imwrite("keypoints.jpg", im_with_keypoints) #cv2.imshow("keypoint", im_with_keypoints) #cv2.waitKey(0) #print("Total of objects") #print(len(keypoints)) # dummy if len(keypoints) > 6: return 1 else: return 0
def detect_electrodes(self, kernel=None): self._kernel = 15 if kernel is None else kernel kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (self._kernel, self._kernel)) mask_closed = cv2.morphologyEx(self._final_mask, cv2.MORPH_CLOSE, kernel) mask_clean = cv2.morphologyEx(mask_closed, cv2.MORPH_OPEN, kernel) _, mask = self.find_electrodes(mask_clean) self._overlay = self.overlay_mask(mask_clean) params = self.some_parameters() ver = cv2.__version__.split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) masked_data = cv2.bitwise_and(self._overlay, self._overlay, mask=mask_clean) key_points = detector.detect(masked_data) # temp = [21, 23, 31, 38, 47, 56, 59, 63] temp = [ 3, 4, 5, 7, 12, 13, 15, 20, 23, 31, 39, 45, 46, 47, 48, 52, 54, 55, 56, 57, 62, 63 ] self._detected_electrodes = np.asarray( [key_point.pt for key_point in key_points]) i, j = self._create_grid() self._electrode_mesh = np.array((i.ravel(), j.ravel())).T self._full_detected_electrodes = self._optimize(visualise=True) final_grid = np.zeros((64, 2)) final_grid[:self._detected_electrodes. shape[0]] = self._detected_electrodes ct = 1 for pt in range(len(final_grid)): if pt in temp: final_grid[self._detected_electrodes.shape[0] - 1 + ct] = self._full_detected_electrodes[pt] ct += 1 return self._full_detected_electrodes, 0.0
def blob_detection(image): """ Takes color image and detects blobs :param image: color image 1920x1080 from camera :return: image with written blobs """ import cv2 import numpy as np # Convert to Gray image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # DETECTOR PARAMETERS params = cv2.SimpleBlobDetector_Params() # Change threshold params.minThreshold = 10; params.maxThreshold = 200; # Filter by Area params.filterByArea = True params.minArea = 1500 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.1 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.87 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0.01 # Set detector with custom 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(image) # Draw blobs image_with_blobs = cv2.drawKeypoints(image, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Show blobs cv2.imshow('Blobs detected', cv2.resize(image_with_blobs, (int(1920/3.5), int(1080/3.5)))) cv2.waitKey(4000) cv2.destroyAllWindows() return image_with_blobs
def refined_blob_detection(self, img): # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Change thresholds params.minThreshold = 10; params.maxThreshold = 200; # Filter by Area. params.filterByArea = True # params.minArea = 1500 params.minArea = 2000 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 1 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.87 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0.01 # 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(img) # 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(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Show keypoints cv2.imshow("Refined Blob Detection", im_with_keypoints) cv2.waitKey(1)
def black_and_yellow_buoys(frame): # define range of yellow in HSV yellow_upper_hsv = np.array([55, 255, 255], dtype="uint8") yellow_lower_hsv = np.array([30, 130, 150], dtype="uint8") # define range of black in HSV black_upper_hsv = np.array([10, 255, 255], dtype="uint8") black_lower_hsv = np.array([0, 100, 100], dtype="uint8") # Threshold the HSV image to get only input colors ylw = cv2.inRange(hsv, yellow_lower_hsv, yellow_upper_hsv) blk = cv2.inRange(hsv, black_lower_hsv, black_upper_hsv) # Bitwise-OR yellow and black result = cv2.bitwise_or(ylw, blk) closing = cv2.morphologyEx(result, cv2.MORPH_CLOSE, kernel2) BuoyBinary = closing # cv2.bitwise_not(closing) #### white = np.array([0, 0, 255], dtype="uint8") whiteClosing = cv2.morphologyEx(white, cv2.MORPH_CLOSE, kernel2) whiteFinal = whiteClosing #### # Set up the detector with default parameters. detector = cv2.SimpleBlobDetector(params) # Detect blobs. keypoints = detector.detect(frame) # Draw detected blobs as red circles (0, 0, 255)BGR # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob im_with_keypoints = cv2.drawKeypoints( BuoyBinary, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.imwrite("frame%d.jpg" % count, frame) cv2.imwrite("binary_%d.jpg" % count, BuoyBinary) cv2.imshow("binary_%d.jpg" % count, BuoyBinary) cv2.imwrite("keypts_%d.jpg" % count, im_with_keypoints) cv2.imshow('keypts', im_with_keypoints)
def blob_detection(img): # Set up the detector with default parameters. detector = cv2.SimpleBlobDetector() # Detect blobs. keypoints = detector.detect(img) # 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( img, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Show keypoints # cv2.imshow("Keypoints", im_with_keypoints) # cv2.waitKey() plt.imshow(im_with_keypoints) plt.title("Blobs") plt.show()
def __init__(self): self.max_clusters = 8 self.threshold = 20 self.blubParams = cv2.SimpleBlobDetector_Params() self.blubParams.minThreshold = 50 self.blubParams.maxThreshold = 255 self.blubParams.filterByArea = True self.blubParams.minArea = 0 self.blubParams.filterByCircularity = True self.blubParams.minCircularity = 0.3 self.blubParams.filterByConvexity = True self.blubParams.minConvexity = 0.7 self.blubParams.filterByInertia = True self.blubParams.minInertiaRatio = 0.1 self.blubParams.blobColor = 255 ver = (cv2.__version__).split('.') if int(ver[0]) < 3: self.blubDetector = cv2.SimpleBlobDetector(self.blubParams) else: self.blubDetector = cv2.SimpleBlobDetector_create(self.blubParams)
def coordinates_question(self, image): try: # Criando o detector baseado na versão do CV is_cv3 = cv2.__version__.startswith("3.") if is_cv3: detector = cv2.SimpleBlobDetector_create() else: detector = cv2.SimpleBlobDetector() # Detectando corpos keypoints = detector.detect(image) im_with_keypoints = cv2.drawKeypoints( image, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) return keypoints except: print("ERROR 'coordinates_question' IMAGE") self.cap.release() cv2.destroyAllWindows() exit(0)
def getContours(theframe): params = cv2.SimpleBlobDetector_Params() params.minThreshold = 245 params.maxThreshold = 255 params.filterByCircularity = True params.minCircularity = .8 detector = cv2.SimpleBlobDetector(params) imgray = cv2.cvtColor(theframe, cv2.COLOR_BGR2GRAY) keypoints = detector.detect(imgray) im_kp = cv2.drawKeypoints(imgray, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) ctrs, hier = cv2.findContours(im_kp, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(thresh, ctrs, -1, (255, 255, 255), 3) cv2.imshow('kps', im_kp) return ctrs
def findblobs(img): #finds all blobs in a given Image # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Change thresholds params.minThreshold = 120 params.maxThreshold = 200 # Filter by Area. params.filterByArea = True params.minArea = 20 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.5 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.8 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0.01 # 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) image = threshholding(img) # Detect blobs. keypoints = detector.detect(image) # 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( img, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) return im_with_keypoints, keypoints, keypoints.__len__()
def return_blobs(self, image, color_min, color_max): img_BGR = cv2.imread(image) # Setup default values for SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # These are just examples, tune your own if needed # Change thresholds params.minThreshold = 10 params.maxThreshold = 200 # Filter by Area params.filterByArea = True params.minArea = 200 params.maxArea = 10000 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.1 # Filter by Color params.filterByColor = False # not directly color, but intensity on the channel input # params.blobColor = 0 params.filterByConvexity = False params.filterByInertia = False mask_color = cv2.inRange(img_BGR, color_min, color_max) # 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) # detector finds "dark" blobs by default, so invert image for results with same detector keypoints_color = detector.detect(255-mask_color) K = [] for k in keypoints_color: K.append((k.pt[0], k.pt[1], k.size)) return K
def EnclosedRegion(line): line = cv2.bitwise_not(line) # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Change thresholds params.minThreshold = 10 params.maxThreshold = 200 # Filter by Area. params.filterByArea = False params.minArea = 50 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.1 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.5 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0.01 # 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(line) Diameter = np.mean([keypoint.size for keypoint in keypoints if keypoint.size > 0]) Length = math.pi * Diameter Area = math.pi * (Diameter**2)/4 return Area
def main(): global blur_image, min_color, max_color, first_color, mask_image color_image = cv2.imread('../start_img.jpg', cv2.IMREAD_COLOR) blur_image = cv2.GaussianBlur(color_image, (5, 5), 0) params = cv2.SimpleBlobDetector_Params() params.minThreshold = 0 params.maxThreshold = 255 params.filterByArea = True params.minArea = 50 params.maxArea = 256 * 256 params.filterByCircularity = False params.minCircularity = 0.1 params.filterByConvexity = False params.minConvexity = 0.9 params.filterByInertia = False params.minInertiaRatio = 0.5 ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) cv2.namedWindow('Blur Image') cv2.setMouseCallback('Blur Image', mouseEvent) cv2.imshow('Blur Image', blur_image) while True: if not first_color: cv2.imshow('Mask', mask_image) key = cv2.waitKey(1) & 0xFF if key == ord('q'): break; elif key == ord(' '): print 'Detecting blobs' keypoints = detector.detect(255 - mask_image) print 'length:', len(keypoints) for x in keypoints: print x.size, x.angle kp_image = cv2.drawKeypoints(blur_image, keypoints, np.array([]), (0, 255, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.imshow('Keypoints', kp_image)
def getStarBlobs(im): im = cv2.erode(im, np.ones((2, 2))) height, width = im.shape[:2] area = height * width # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Change thresholds params.minThreshold = 4 params.maxThreshold = 255 # Filter by Area. params.filterByArea = True #10000 #500 params.minArea = area / 6596 params.maxArea = area / 711 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0 params.maxCircularity = 255 # Filter by Convexity params.filterByConvexity = False params.minConvexity = 0 params.maxConvexity = 255 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0 ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector(params) else: detector = cv2.SimpleBlobDetector_create(params) keypoints = detector.detect(im) return keypoints #,im
def detect_blobs(self, image): # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() params.filterByArea = True params.minArea = 200 params.filterByColor = True params.blobColor = 255 params.filterByCircularity = False params.filterByConvexity = False params.filterByInertia = False # 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) blobs = detector.detect(image) return blobs
def blob(): # Read image im = cv2.imread("raw_footage\\1.jpeg", cv2.IMREAD_GRAYSCALE) cv2.imshow("Keypoints", im) cv2.waitKey(0) # Set up the detector with default parameters. detector = cv2.SimpleBlobDetector() # 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.imshow("Keypoints", im_with_keypoints) cv2.waitKey(0)
def blob_detect(image): global size_point global space_point blob = (size_point, space_point) detector = cv2.SimpleBlobDetector() # Detect blobs keypoints = detector.detect(image) new_keypoints = [] # filter blob on size for points in keypoints: if points.size >= blob[0]: new_keypoints = new_keypoints + [points] keypoints = color.remove_double(new_keypoints, blob[1]) # 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 return cv2.drawKeypoints(image, keypoints, np.array([]), (255, 0, 0),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS),keypoints
def create_blob_detector(self): params = cv2.SimpleBlobDetector_Params( ) # Create blob detector with parameters. params.filterByArea = True # Filter blobs by total area. params.minArea = 700 # Minimum area of a blob to be detected. params.maxArea = 15000 # Maximum area of a blob to be detected. params.filterByColor = True # Filter blobs by colour. params.blobColor = 255 # Only detect white spots as blobs. params.filterByCircularity = False # Do not filter by circularity of blobs. params.filterByConvexity = False # Do not filter by convexity of blobs. params.filterByInertia = False # Do not filter by inertia of blobs. ver = cv2.__version__.split( '.') # Set version of blob detector created. if int(ver[0]) < 3: self.detector = cv2.SimpleBlobDetector( params) # Create blob detector. else: self.detector = cv2.SimpleBlobDetector_create( params) # Create blob detector.
def cell_detect_via_blob(frame): resize_ratio, orignal = filters.applyPrimaryFilteringOnImage( frame, last_thresh_min=40) # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.1 # Create a detector with the parameters ver = (cv2.__version__).split('.') if int(ver[0]) < 3: detector = cv2.SimpleBlobDetector() else: detector = cv2.SimpleBlobDetector_create() keypoints = detector.detect(orignal) print keypoints processedframe = cv2.drawKeypoints( orignal, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) return processedframe
def create_blob_detector(blob_min_area=12, blob_min_int=0.0, blob_max_int=1.0, blob_th_step=5): params = cv2.SimpleBlobDetector_Params() params.filterByArea = True params.minArea = blob_min_area params.maxArea = 30 params.filterByCircularity = False params.filterByColor = False params.filterByConvexity = False params.filterByInertia = False # blob detection only works with "uint8" images. params.minThreshold = int(blob_min_int * 255) params.maxThreshold = int(blob_max_int * 255) params.thresholdStep = blob_th_step ver = (cv2.__version__).split('.') if int(ver[0]) < 3: return cv2.SimpleBlobDetector(params) else: return cv2.SimpleBlobDetector_create(params)
def getBlobDetector(exParams): key = 'detector_params' params = cv2.SimpleBlobDetector_Params() params.minThreshold = 0 params.maxThreshold = 256 params.filterByArea = True params.minArea = 300 params.maxArea = 20000 params.filterByCircularity = False params.minCircularity = 0.1 params.filterByConvexity = False params.minConvexity = 0.5 ver = cv2.__version__.split('.') if int(ver[0]) < 3: return cv2.SimpleBlobDetector(params) else: return cv2.SimpleBlobDetector_create(params)
def create_detector(self): """ @brief Setup SimpleBlobDetector parameters. @param None @return detector object """ # Change thresholds self.params.minThreshold = params["blob_detector"]["minThreshold"] self.params.maxThreshold = params["blob_detector"]["maxThreshold"] # Filter by Area. self.params.filterByArea = params["blob_detector"]["filterByArea"] self.params.minArea = params["blob_detector"]["minArea"] self.params.maxArea = params["blob_detector"]["maxArea"] # Filter by Circularity self.params.filterByCircularity = params["blob_detector"][ "filterByCircularity"] self.params.minCircularity = params["blob_detector"]["minCircularity"] # Filter by Convexity self.params.filterByConvexity = params["blob_detector"][ "filterByConvexity"] self.params.minConvexity = params["blob_detector"]["minConvexity"] # Filter by Inertia self.params.filterByInertia = params["blob_detector"][ "filterByInertia"] self.params.minInertiaRatio = params["blob_detector"][ "minInertiaRatio"] # Create a detector with the parameters ver = (cv2.__version__).split('.') if int(ver[0]) < 3: return cv2.SimpleBlobDetector(self.params) else: return cv2.SimpleBlobDetector_create(self.params)
def detect_markers(): width = 1000 height = 1200 # Read image im = cv2.imread("./markers.png", cv2.IMREAD_GRAYSCALE) im = cv2.resize(im, (width, height)) # Setup SimpleBlobDetector parameters. params = cv2.SimpleBlobDetector_Params() params.filterByCircularity = True params.maxCircularity = .85 params.minCircularity = .785 MAX_WIDTH = 215.9 MAX_HEIGHT = 279.4 # 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 points = filterKeypoint(keypoints, width / 215.9, height / 279.4) # for keypoint in keypoints: # print(keypoint.pt[0], keypoint.pt[1]) for p in points: print(p) im_with_keypoints = cv2.drawKeypoints( im, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Show blobs cv2.imshow("Keypoints", im_with_keypoints) cv2.waitKey(0)
def blob_function(img, is_utility): params = cv2.SimpleBlobDetector_Params() params.minThreshold = 10 params.maxThreshold = 256 # Filter by Circularity params.filterByCircularity = True params.minCircularity = 0.8 # Filter by Area. params.filterByArea = True if (is_utility): params.minArea = 14 else: params.filterByArea = True params.minArea = 30 # Filter by Convexity params.filterByConvexity = True params.minConvexity = 0.87 # Filter by Inertia params.filterByInertia = True params.minInertiaRatio = 0.1 params.filterByColor = True params.blobColor = 255 # 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(img) return keypoints