Exemplo n.º 1
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
Exemplo n.º 2
0
 def test_get_semantic(self):
     name = 'SUNRGBD/kv1/NYUdata/NYU0899'
     image, image_size = get_image(name)
     print('image_size: ' + str(image_size))
     semantic = get_category(name, image_size)
     semantic = to_bgr(semantic)
     cv.imwrite('temp/test_get_semantic_image.png', image)
     cv.imwrite('temp/test_get_semantic_semantic.png', semantic)
Exemplo n.º 3
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)
Exemplo n.º 4
0
    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')

    #cv.imwrite('images/test_image.png', image)
    #cv.imwrite('images/test_merged.png', ret)
    #cv.imwrite('images/test_out.png', out)
    cv.imshow('image', image)
    # cv.imshow('ret', ret)
    cv.imshow('out', out)
    cv.waitKey(0)
    K.clear_session()