def __init__(self, left, top, width, height, img=None, img_file=None, threshold=0.9, fg_method=None, bg_method=None, orig_threshold=0.7, debug=False, label=None, call_plugins=None): self.top = top self.left = left self.width = width self.height = height self.threshold = threshold self.orig_threshold = orig_threshold self.debug = debug self.label = label self._call_plugins = call_plugins self.fg_method = fg_method if self.fg_method is None: self.fg_method = MM_WHITE() self.bg_method = bg_method if self.bg_method is None: self.bg_method = MM_NOT_WHITE() if not img_file is None: img_file2 = self._find_image_file(img_file) img = imread(img_file2) if img is None: IkaUtils.dprint('%s is not available. Retrying with %s' % (img_file2, img_file)) img = imread(img_file) if img is None: raise Exception('Could not load mask image %s (%s)' % (label, img_file)) if len(img.shape) > 2 and img.shape[2] != 1: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cropped = (img.shape[0] == self.height) and (img.shape[1] == self.width) if cropped: self.mask_img = img else: self.mask_img = img[top:top + height, left:left + width]
def __init__(self, left, top, width, height, img=None, img_file=None, threshold=0.9, fg_method=None, bg_method=None, orig_threshold=0.7, debug=False, label=None, call_plugins=None): self.top = top self.left = left self.width = width self.height = height self.threshold = threshold self.orig_threshold = orig_threshold self.debug = debug self.label = label self._call_plugins = call_plugins self.fg_method = fg_method if self.fg_method is None: self.fg_method = MM_WHITE() self.bg_method = bg_method if self.bg_method is None: self.bg_method = MM_NOT_WHITE() if not img_file is None: img_file2 = self._find_image_file(img_file) img = imread(img_file2) if img is None: IkaUtils.dprint( '%s is not available. Retrying with %s' % (img_file2, img_file)) img = imread(img_file) if img is None: raise Exception('Could not load mask image %s (%s)' % (label, img_file)) if len(img.shape) > 2 and img.shape[2] != 1: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cropped = (img.shape[0] == self.height) and ( img.shape[1] == self.width) if cropped: self.mask_img = img else: self.mask_img = img[top: top + height, left: left + width]
def loadMask(file, left, top, width, height): mask = imread(file) if mask is None: print("マスクデータ %s のロードに失敗しました") # raise a exception mask = mask[top:top + height, left:left + width] # BGR to GRAY if mask.shape[2] > 1: mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY) return mask