Exemple #1
0
def getRawCroppedImageBlob(roidb, records, scale_inds, getCropped):
    """Builds an input blob from the images in the roidb at the specified
    scales.
    """
    num_images = len(roidb)
    processed_ims = []
    im_scales = []
    for idx, roi in enumerate(roidb):
        im = cv2.imread(roi['image'])
        if roi['flipped']:
            im = im[:, ::-1, :]
        target_size = cfg.TRAIN.SCALES[0]
        cimg = im
        if getCropped:
            cimg = cropImageToAnnoRegion(
                im, roi['boxes']
                [0])  # always the first box since we are *flattened*
        target_size = cfg.TRAIN.SCALES[0]
        cimg, cimg_scale = prep_im_for_blob(cimg, cfg.PIXEL_MEANS, target_size,
                                            cfg.TRAIN.MAX_SIZE)
        cimg_scale = 1.0  # why always "1.0"??
        processed_ims.append(cimg)
        im_scales.append(cimg_scale)
    # Create a blob to hold the input images
    blob = im_list_to_blob(processed_ims)

    return blob, im_scales
def HOGfromRoidbSample(sample,
                       orient=9,
                       pix_per_cell=8,
                       cell_per_block=2,
                       hog_channel=0):
    features = []
    img = cv2.imread(sample['image'])
    for box in sample['boxes']:
        clean_box(box, sample)
        cimg = cropImageToAnnoRegion(img, box)
        feature_image = np.copy(cimg)
        try:
            features.append(HOGFromImage(feature_image))
        except:
            print(sample)
            return None
    return features
Exemple #3
0
def loadImage(imdb, image_path, image_index, bbox, al_net, idx):
    isImBlob = False
    if imdb.is_image_index_flattened and al_net is None:
        raw_img = cv2.imread(image_path)
        img = cropImageToAnnoRegion(raw_img, bbox)
    elif imdb.is_image_index_flattened and al_net is not None:
        sampleRoidb = [imdb.roidb[idx]]
        sampleRoidb[0]['image'] = image_path
        sampleRecords = []
        numClasses = len(cfg.DATASETS.CLASSES)
        input_data = alcls_get_minibatch(sampleRoidb, sampleRecords, al_net,
                                         numClasses)
        img = {}
        img['data'] = input_data['data']
        isImBlob = True
    else:
        img = cv2.imread(image_path)
    return img, isImBlob
Exemple #4
0
def bboxHOGfromRoidbSample(sample,orient=9, pix_per_cell=8,
                       cell_per_block=2, hog_channel=0):
    features = []
    if 'image' not in sample.keys():
        # print(sample)
        print(sample.keys())
        print("WARINING [bboxHOGfromRoidbSample]: the\
        image field is not available for the above sample")
        return None
    img = cv2.imread(sample['image'])
    for box in sample['boxes']:
        box = clean_box(box,sample['width'],sample['height'])
        cimg = cropImageToAnnoRegion(img,box)
        feature_image = np.copy(cimg)      
        try:
            features.append(HOGFromImage(feature_image))
        except Exception as e:
            print(e)
            print('hog failed @ path {}'.format(sample['image']))
            return None
    return features
                d[sline[0]] = [{
                    "path": sline[1],
                    "box": map(int, sline[2].split("_")),
                    "score": float(sline[3])
                }]
    return d


if __name__ == '__main__':
    args = parse_args()

    print('Called with args:')
    print(args)

    setID = args.setID
    repeat = args.repeat
    size = args.size

    fn = constructFilenameToLoad(setID, repeat, size)
    ntdResults = loadNtdFile(fn)
    pprint.pprint(ntdResults)
    for dataset, iconicSamples in ntdResults.items():
        for iconicSample in iconicSamples:
            img = cv2.imread(iconicSample['path'])
            box = iconicSample['box']
            score = iconicSample['score']
            cimg = cropImageToAnnoRegion(img, box)
            saveFn = constructFilenameToSaveImage(setID, repeat, size, dataset,
                                                  score)
            cv2.imwrite(saveFn, cimg)