Ejemplo n.º 1
0
    def test_safe_crop(self):
        name = 'SUNRGBD/kv1/NYUdata/NYU0899'
        image, image_size = get_image(name)
        semantic = get_category(name, image_size)
        different_sizes = [(320, 320), (480, 480), (640, 640)]
        crop_size = random.choice(different_sizes)

        x, y = random_choice(image_size, crop_size)
        image = safe_crop(image, x, y, crop_size)
        semantic = safe_crop(semantic, x, y, crop_size)
        semantic = to_bgr(semantic)
        cv.imwrite('temp/test_safe_crop_image.png', image)
        cv.imwrite('temp/test_safe_crop_semantic.png', semantic)
Ejemplo n.º 2
0
def classify_image(image_data):
    img_array = np.fromstring(image_data, dtype=np.uint8)
    image = cv.imdecode(img_array, cv.IMREAD_COLOR)
    image_size = image.shape[:2]

    x, y = random_choice(image_size)
    image = safe_crop(image, x, y)
    print('Start processing image...')

    x_test = np.empty((1, img_rows, img_cols, 3), dtype=np.float32)
    x_test[0, :, :, 0:3] = image / 255.

    out = model.predict(x_test)
    out = np.reshape(out, (img_rows, img_cols, num_classes))
    out = np.argmax(out, axis=2)
    out = to_bgr(out)

    ret = image * 0.6 + out * 0.4
    ret = ret.astype(np.uint8)

    K.clear_session()
    is_success, buffer = cv.imencode(".png", out)
    buffer
    out_bytes = BytesIO(buffer)
    return out_bytes
Ejemplo n.º 3
0
    filename = './single_human_paring/img/man/unexpose/img_023.jpg'
    img_rows, img_cols = 320, 320
    channel = 3

    model_weights_path = 'Look_Into_Person/models/model.11-0.8409.hdf5'
    model = build_model()
    model.load_weights(model_weights_path)

    print(model.summary())

    image = cv.imread(filename)
    image = cv.resize(image, (img_rows, img_cols), cv.INTER_CUBIC)
    image_size = image.shape[:2]

    x, y = random_choice(image_size)
    image = safe_crop(image, x, y)
    print('Start processing image: {}'.format(filename))

    x_test = np.empty((1, img_rows, img_cols, 3), dtype=np.float32)
    x_test[0, :, :, 0:3] = image / 255.

    out = model.predict(x_test)
    out = np.reshape(out, (img_rows, img_cols, num_classes))
    out = np.argmax(out, axis=2)
    out = to_bgr(out)
    #
    # ret = image * 0.6 + out * 0.4
    # ret = ret.astype(np.uint8)

    #if not os.path.exists('images'):
    #    os.makedirs('images')
Ejemplo n.º 4
0
                   os.path.isfile(os.path.join(rgb_test_path, f)) and f.endswith('.png')]

    samples = random.sample(test_images, 10)

    for i in range(len(samples)):
        image_name = samples[i]
        filename = os.path.join(rgb_test_path, image_name)
        image = cv.imread(filename)
        label = get_semantic(image_name)
        image_size = image.shape[:2]
        different_sizes = [(320, 320), (480, 480), (480, 480), (480, 480), (640, 640), (640, 640), (640, 640),
                           (960, 960), (960, 960), (960, 960)]
        crop_size = random.choice(different_sizes)

        x, y = random_choice(image_size, crop_size)
        image = safe_crop(image, x, y, crop_size)
        label = safe_crop(label, x, y, crop_size)
        print('Start processing image: {}'.format(filename))

        x_test = np.empty((1, img_rows, img_cols, 3), dtype=np.float32)
        x_test[0, :, :, 0:3] = image / 255.

        out = model.predict(x_test)
        out = np.reshape(out, (img_rows, img_cols, num_classes))
        out = np.argmax(out, axis=2)
        out = to_bgr(out)

        str_msg = 'crop_size: %s' % (str(crop_size))
        draw_str(out, (20, 20), str_msg)

        if not os.path.exists('images'):