Esempio n. 1
0
def show_data(file_name, error_list):
    with open(file_name) as f:
        lines = f.readlines()
    shuffle(lines)
    for line in lines:
        line = line.strip().split('\t')

        if int(line[0]) not in error_list:
            if int(line[0]) > (5466 + 4698):
                print(line[0])

                poly = list(map(int, line[2].split(',')))
                bbox = [
                    min(poly[::2]),
                    min(poly[1::2]),
                    max(poly[::2]),
                    max(poly[1::2])
                ]

                image = cv_load_image(line[1])
                image = cv2.putText(image, line[-1], (bbox[0], bbox[1] + 20),
                                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255),
                                    2)
                image = cv2.rectangle(image, (bbox[0], bbox[1]),
                                      (bbox[2], bbox[3]), (0, 0, 255), 2)
                cv2.imshow('image', image)
                cv2.waitKey()
                key = cv2.waitKey()
                if key & 0xFF == ord('q'):
                    break
Esempio n. 2
0
 def imloader(path, loader='OPNENCV'):
     assert loader in ('OPENCV', 'PIL'), 'Only support OPENCV, PIL for now.'
     if loader == 'OPENCV':
         return cv_load_image(path)
     else:
         if os.path.exists(path):
             return Image.open(path).convert('RGB')
         else:
             imfile = requests.get(path)
             return Image.open(BytesIO(imfile.content)).convert('RGB')
Esempio n. 3
0
def show_gt():
    file1 = "/core/data/dataset/biaozhu/yf_filtr/air_test.json"
    with open(file1, 'r', encoding='utf8')as fp:
        json_data = json.load(fp)
    count = 0
    cv2.namedWindow("enhanced", 0)
    cv2.resizeWindow("enhanced", 1920, 1080)

    for image in json_data['images']:
        url = image['file_name']
        img = cv_load_image(url)
        count += 1
        print(count)
        imgStack = stackImages(0.5, ([img, ],))
        cv2.imshow("enhanced", img)
        cv2.waitKey(0)
Esempio n. 4
0
    def worker(self, data):
        imp = data[0]
        flipped = data[2]
        pixel_means = self.cfg.network.PIXEL_MEANS
        #im = cv2.imread(imp, cv2.IMREAD_COLOR)
        im = cv_load_image(imp)
        # Flip the image
        if flipped:
            im = im[:, ::-1, :]

        # Crop if required
        if self.crop_size:
            crop = data[1]
            max_size = [self.crop_size, self.crop_size]
            im = im[int(crop[0][1]):int(crop[0][3]), int(crop[0][0]):int(crop[0][2]), :]
            scale = crop[1]
        else:
            max_size = data[1]
            # Compute scale based on config
            min_target_size = self.target_size[0]
            max_target_size = self.target_size[1]
            im_size_min = np.min(im.shape[0:2])
            im_size_max = np.max(im.shape[0:2])
            scale = float(min_target_size) / float(im_size_min)
            if np.round(scale * im_size_max) > max_target_size:
                scale = float(max_target_size) / float(im_size_max)
        # Resize the image
        try:
            im = cv2.resize(im, None, None, fx=scale, fy=scale, interpolation=cv2.INTER_LINEAR)
        except:
            print 'Image Resize Failed!'

        rim = np.zeros((3, max_size[0], max_size[1]), dtype=np.float32)
        d1m = min(im.shape[0], max_size[0])
        d2m = min(im.shape[1], max_size[1])

        for j in range(3):
            rim[j, :d1m, :d2m] = im[:d1m, :d2m, 2 - j] - pixel_means[2 - j]

        if self.crop_size:
            return mx.nd.array(rim, dtype='float32')
        else:
            return mx.nd.array(rim, dtype='float32'), scale, (im.shape[0],im.shape[1])
Esempio n. 5
0
def vis_prop(fn, boxes, scores, labels):
    def add_object_on_image(image, box, score, posi=True):
        b = list(map(int, box))
        text = '{:.4f}'.format(score)
        c = (255, 0, 0) if posi else (0, 0, 255)
        cv2.rectangle(image, (b[0], b[1]), (b[2], b[3]), c, thickness=1)
        font = cv2.FONT_HERSHEY_SIMPLEX
        tag_font_scale = 0.3
        ((txt_w, txt_h), _) = cv2.getTextSize(text, font, tag_font_scale, 1)
        txt_tl = b[0], b[1] + int(1. * txt_h)

        cv2.putText(image, text, txt_tl, font, tag_font_scale, c, lineType=cv2.LINE_AA)
        return image

    image = cv_load_image(fn)

    for b, s, l in zip(boxes, scores, labels):
        image = add_object_on_image(image, b, s, l > 0)

    cv2.imshow('prop', image)
    cv2.waitKey()
Esempio n. 6
0
    #
    #     # mor = cv2.erode(binary, kernel=np.ones((3, 3), np.uint8), iterations=7)
    #     # mor = cv2.dilate(mor, kernel=np.ones((3, 3), np.uint8), iterations=7)
    #     # imgCanny = cv2.Canny(binary, 100, 100)
    #     # imgBlank = np.zeros_like(img)
    #
    #     getContours(binary, imgContour)
    #     # getContours(mor, imgContour1)
    #
    #     imgStack = stackImages(0.5, ([imgContour, ],))
    #     # new_filename = os.path.join(root, 'new_' + name)
    #     # cv2.imwrite(new_filename, imgStack)
    #
    #     cv2.imshow('test', imgStack)
    #     cv2.waitKey(0)
    img0 = cv_load_image('http://192.168.7.29:8081/334,0b3b1f438b259f1b')
    orig_img0 = img0.copy()
    a = torch.load('/data4t/data/zhangyufei/data/pk0.pth', map_location='cpu')
    print('torch load: ', a)
    b = a[0].bbox.numpy().tolist()
    print('num of proposal: ', len(b))
    for c in b:
        cv2.rectangle(img0, (int(c[0]), int(c[1])), (int(c[2]), int(c[3])), (0, 0, 255), 1)

    img2 = cv_load_image('http://192.168.7.13:8081/82,0b3b1fbc39e81393')
    orig_img2 = img2.copy()
    a = torch.load('/data4t/data/zhangyufei/data/pk2.pth', map_location='cpu')
    print('torch load: ', a)
    b = a[0].bbox.numpy().tolist()
    print('num of proposal: ', len(b))
    for c in b:
Esempio n. 7
0
        return w, 0, img
    vertical_group = [x for x in consecutive(vertical) if (len(x) > 20)]
    if len(vertical_group) == 0:
        return w, 0, img
    elif len(vertical_group) == 1:
        if vertical_group[0][0] == 0:
            r, l = (w, vertical_group[0][-1])
        elif vertical_group[0][-1] == w - 1:
            r, l = (vertical_group[0][0], 0)
        else:
            r, l = w, 0
    elif len(vertical_group) >= 2:
        if vertical_group[-1][-1] == w - 1 and vertical_group[0][0] == 0:
            r, l = (min(vertical_group[-1]), max(vertical_group[0]))
        else:
            r, l = w, 0
    else:
        r, l = w, 0

    if r - l + 1 <= 1000:
        return w, 0, img

    return r, l, img[:, l:r, :]


if __name__ == "__main__":
    import sys
    from cvtools import cv_load_image
    img = cv_load_image(sys.argv[1])
    print(clamp(img))
Esempio n. 8
0
    for image in json_data['images']:
        url = image['file_name']
        img = cv_load_image(url)
        count += 1
        print(count)
        imgStack = stackImages(0.5, ([img, ],))
        cv2.imshow("enhanced", img)
        cv2.waitKey(0)


file1 = "/core/data/dataset/biaozhu/yf_wuxi/val_wuxi.json"
with open(file1, 'r', encoding='utf8')as fp:
    json_data = json.load(fp)

pic_dir_root = "/core/data/dataset/biaozhu/yf_box"
if not os.path.exists(pic_dir_root):
    os.makedirs(pic_dir_root)

count = 0
for image in json_data['images']:
    pic_file_name = os.path.join(pic_dir_root, str(image['id']) + '.jpg')
    print(pic_file_name)
    url = image['file_name']
    img = cv_load_image(url)

    # cv2.imwrite(pic_file_name, img)
    count += 1

print(count)