示例#1
0
    def fetch_image(self):
        # load
        if os.path.exists(self.image_path) is not True:
            raise IOError("File does not exist: %s" % self.image_path)
        img = load_image(self.image_path)
        self.origin_height = img.shape[0]
        self.origin_width = img.shape[1]

        # resize
        if img.shape[0] > img.shape[1]:
            scale = 1.0 * self.max_edge / img.shape[0]
        else:
            scale = 1.0 * self.max_edge / img.shape[1]

        h, w = int(self.origin_height * scale), int(self.origin_width * scale)
        h, w = h - h%16, w - w%16
        img = cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)

        img = sub_mean(img)
        if self.flipped:
            img = img[:, ::-1, :]
        self.height = img.shape[0]
        self.width = img.shape[1]

        self.image = img
        self.img_blob = self.image.transpose((2, 0, 1))
        self.img_blob = self.img_blob[np.newaxis, ...]

        self.scale = scale
        self.objAttMaskScales = []

        return {'image': self.img_blob}
示例#2
0
    def fetch_image(self):
        # load
        if os.path.exists(self.image_path) is not True:
            raise IOError("File does not exist: %s" % self.image_path)
        img = load_image(self.image_path)
        self.origin_height = img.shape[0]
        self.origin_width = img.shape[1]

        # resize
        if img.shape[0] > img.shape[1]:
            scale = 1.0 * self.max_edge / img.shape[0]
        else:
            scale = 1.0 * self.max_edge / img.shape[1]

        h, w = int(self.origin_height * scale), int(self.origin_width * scale)
        # make sure that w and h
        # could be divisible by 4
        # so that we can get a
        # predictable sized feature
        # map from body net.
        h, w = h - h % 4, w - w % 4
        img = cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)
        img = sub_mean(img)
        if self.flipped:
            img = img[:, ::-1, :]
        self.height = img.shape[0]
        self.width = img.shape[1]

        self.image = img
        self.img_blob = self.image.transpose((2, 0, 1))
        self.img_blob = self.img_blob[np.newaxis, ...]

        self.scale = scale

        return {'image': self.img_blob}
示例#3
0
    # image pre-processing
    img = load_image(args.input_image)
    img_org = img.copy()[:,:,::-1]
    origin_height = img.shape[0]
    origin_width = img.shape[1]

    if img.shape[0] > img.shape[1]:
        scale = 1.0 * config.TEST_SCALE / img.shape[0]
    else:
        scale = 1.0 * config.TEST_SCALE / img.shape[1]

    h, w = int(origin_height * scale), int(origin_width * scale)
    h, w = h - h % 16, w - w % 16

    img = cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)
    img = sub_mean(img)

    img_blob = img.transpose((2, 0, 1))
    img_blob = img_blob[np.newaxis, ...]

    # all masks with all scores (1000 in total)
    ret_masks, ret_scores = gen_masks_new(net, img_blob, config, dest_shape=(origin_height, origin_width))

    # display top 20 masks
    for i in np.argsort(ret_scores)[::-1][:20]:
        mask = ret_masks[i].copy()
        color = np.array(colors[i%len(colors)])
        mask = np.dstack([mask]*3)
        colorMask = color*mask
        img_org=img_org*(1-mask)+mask*img_org*.5+colorMask*.5
        img_org = mark_boundaries(img_org,mask[:,:,0],color=color.tolist(),mode='thick')