def gen_regions(image, dims, pad): """ Generates candidate regions for object detection using selective search """ assert(len(dims) == 3) img = skimage.io.imread(image) start = time.time() regions = selective_search(img, ks=[100]) print("Selective search time: %.2f [s]" % (time.time() - start)) resize_t = 0 crops = [] for conf, (x0, y0, x1, y1) in regions: if x0-pad >= 0: x0 = x0-pad if y0-pad >= 0: y0 = y0-pad if x1+pad <= dims[0]: x1 = x1+pad if y1+pad <= dims[0]: y1 = y1+pad region = img[x0:x1, y0:y1, :] st = time.time() candidate = resize(region, dims) resize_t += time.time() - st crops.append( (conf, candidate, region) ) print("Resize time: %.2f [s]" % resize_t) return crops
def gen_regions(image, dims, pad, ks): """ Generates candidate regions for object detection using selective search. """ print "Generating cropped regions..." assert(len(dims) == 3) regions = selective_search(image, ks=[ks], feature_masks=[features.SimilarityMask( size=1, color=1, texture=1, fill=1, )]) crops = [] for conf, (y0, x0, y1, x1) in regions: if x0 - pad >= 0: x0 = x0 - pad if y0 - pad >= 0: y0 = y0 - pad if x1 + pad <= dims[0]: x1 = x1 + pad if y1 + pad <= dims[0]: y1 = y1 + pad # Images are rows, then columns, then channels. region = image[y0:y1, x0:x1, :] candidate = resize(region, dims) crops.append((conf, candidate, region, (x0, y0, x1, y1))) print "Generated {} crops".format(len(crops)) return crops
def gen_regions(image, dims, pad): """ Generates candidate regions for object detection using selective search """ assert (len(dims) == 3) img = skimage.io.imread(image) start = time.time() regions = selective_search(img, ks=[100]) print("Selective search time: %.2f [s]" % (time.time() - start)) resize_t = 0 crops = [] for conf, (x0, y0, x1, y1) in regions: if x0 - pad >= 0: x0 = x0 - pad if y0 - pad >= 0: y0 = y0 - pad if x1 + pad <= dims[0]: x1 = x1 + pad if y1 + pad <= dims[0]: y1 = y1 + pad region = img[x0:x1, y0:y1, :] st = time.time() candidate = resize(region, dims) resize_t += time.time() - st crops.append((conf, candidate, region)) print("Resize time: %.2f [s]" % resize_t) return crops
def belltailp_search(self, image): image_ubyte = img_as_ubyte(image) candidates = set() # Actual selective search with some tunable settings, for more # information look at it's github page # feature_masks(Texture, Color, Fill, Size) regions = selective_search(image_ubyte, color_spaces=['rgb'], ks=[500, 100], feature_masks=[(1, 0, 0, 1), (0, 1, 1, 0)]) # Fill in candidates for region in regions: size, (y0, x0, y1, x1) = region candidate = (x0, y0, x1, y1) candidates.add(candidate) result = self.render_valid_candidates(image, candidates) return result
def gen_regions(image, dims, pad, ks): """ Generates candidate regions for object detection using selective search. """ print "Generating cropped regions..." assert (len(dims) == 3) regions = selective_search(image, ks=[ks], feature_masks=[ features.SimilarityMask( size=1, color=1, texture=1, fill=1, ) ]) crops = [] for conf, (y0, x0, y1, x1) in regions: if x0 - pad >= 0: x0 = x0 - pad if y0 - pad >= 0: y0 = y0 - pad if x1 + pad <= dims[0]: x1 = x1 + pad if y1 + pad <= dims[0]: y1 = y1 + pad # Images are rows, then columns, then channels. region = image[y0:y1, x0:x1, :] candidate = resize(region, dims) crops.append((conf, candidate, region, (x0, y0, x1, y1))) print "Generated {} crops".format(len(crops)) return crops