def loadTargetImage(self, src, remove_bg=True): tmp = cv2.imread(src, cv2.IMREAD_GRAYSCALE) if tmp is None: raise Exception('Cant load image from file %s' % (src, )) cam = self.systemModel.cam if tmp.shape != (cam.height, cam.width): # visit fails to generate 1024 high images tmp = cv2.resize(tmp, None, fx=cam.width / tmp.shape[1], fy=cam.height / tmp.shape[0], interpolation=cv2.INTER_CUBIC) if BATCH_MODE and self.add_image_noise and self._noise_image: tmp = ImageProc.add_noise_to_image(tmp, self._noise_image) self.image_file = src if remove_bg: self.full_image, h, th = ImageProc.process_target_image(tmp) self.image_bg_threshold = th self.parent().centroid.bg_threshold = th else: self.full_image = tmp self.image_bg_threshold = None self.parent().centroid.bg_threshold = None self.setImageZoomAndResolution(im_scale=self.im_def_scale)
def remove_background(self, img): res_img, h, th = ImageProc.process_target_image(img) return res_img, th