def process_folder(self, folder): """ Process folder Returns: (positive, negative) Tuple with two lists: positive and negative file names """ return self.process_file_list(FileHelper.read_images_in_dir(folder))
def tag_folder(self, folder, output): print folder if folder[-1] == '\\': folder = folder[:-1] self.currentFolder = folder self.uplevelFolder = os.path.split(folder)[-1] try: self.currentTag = getTagCoordinates(self.uplevelFolder, YX=False) except ValueError: pass self.negativePath = os.path.join(output, 'negative') self.goodPath = os.path.join(output, 'good') self.badPath = os.path.join(output, 'bad') self.awfulPath = os.path.join(output, 'awful') self.twitterPath = os.path.join(output, 'twitter') self.facebookPath = os.path.join(output, 'facebook') self.atPath = os.path.join(output, 'at') self.filelist = sorted(FileHelper.read_images_in_dir(folder, includeDir=True)) if not self.show_next(): shutil.rmtree(folder) return True while True: action = self.wait_for_action() if action == 'break': return False elif action == 'next': if not self.show_next(): shutil.rmtree(folder) return True
def __load_prepare_templates(self): """Load templates. Template MUST be white on black background""" templates = [] filelist = sorted(FileHelper.read_images_in_dir(self.templates_dir)) for filename in filelist: templ = self.__load_template(os.path.join(self.templates_dir, filename)) if templ is not None: templates.append(templ) return templates
def __getFeaturesFromTemplates(self): features = {} images = FileHelper.read_images_in_dir(self.templates_dir) for filename in images: im = cv2.imread(os.path.join(self.templates_dir, filename), cv2.IMREAD_GRAYSCALE) kp, desc = self.detector.detectAndCompute(im, None) logging.debug('{0} - {1} features'.format(filename, len(kp))) # features.append((kp, desc)) features[filename] = (kp, desc) return features
def binarize_folder_threshold(inFolder, outFolder): fileList = FileHelper.read_images_in_dir(inFolder) FileHelper.create_or_clear_dir(outFolder) for filename in fileList: image = load_image_thresholding(os.path.join(inFolder, filename), 190) cv2.imwrite(os.path.join(outFolder, filename), image)
def process_folder(folder, rules=default_sample): files = FileHelper.read_images_in_dir(folder) return get_ruled_files(files, rules)
def process_folder(classifier, inputFolder, countPositive, positiveOutputFolder=None, negativeOutputFolder=None, jobs=-1): filelist = [os.path.join(inputFolder, fn) for fn in FileHelper.read_images_in_dir(inputFolder)] return process_file_list(classifier, filelist, countPositive, positiveOutputFolder, negativeOutputFolder, jobs)
base_template = drawContours(base_template, template_contours) cv2.imwrite('/home/valeriy/projects/hashtag/logos/bw/twitter_big_template_contours.png', base_template) if len(template_contours) > 1: print 'Warning: too complex template' template_contours = template_contours[0] # print len(template_contours) print '%0.3f %3d %0.2f %0.2f ' % (0.0, len(template_contours), contourSolidity(template_contours), contourExtent(template_contours)) # template_contours = approxContour(template_contours) inFolder = '/home/valeriy/projects/hashtag/logos/twitter_frames/' outFolder = '/home/valeriy/projects/hashtag/logos/bin_twitter_frames/' FileHelper.create_or_clear_dir(outFolder) for filename in sorted(FileHelper.read_images_in_dir(inFolder))[:3]: print filename basefile = os.path.join(inFolder, filename) basefile_without_ext = os.path.join(outFolder, os.path.splitext(filename)[0]) # image = binarization.load_image_adaptive(basefile, 11, 10, inverse=False) image = binarization.load_image_thresholding(basefile, 180) # image = binarization.load_image_thresholding(basefile, 200, binary_type=cv2.THRESH_BINARY_INV) contour_image = image.copy() contours, hierarchy = cv2.findContours(contour_image, cv2.RETR_TREE, findContourMethod) image_drawed = drawContours(image, contours) # cv2.imwrite(basefile_without_ext + '_bin_thresh_100.jpg', image_drawed) # cv2.imwrite(basefile_without_ext + '_contour.jpg', contour_image) # contours = approxAllContours(contours) image = contour_match(template_contours, contours, image)