import xlrd
import cv2
import os
from demo.three_color import handle_from_url, handle_from_path


def read_excel():
    data = xlrd.open_workbook('20190515衣服测试链接.xlsx')
    table = data.sheets()[0]
    nrows = table.nrows
    for i in range(1, nrows+1):
        url = table.row_values(i)[0]
        tag = table.row_values(i)[1]
        path = url.split('/')[-1]
        path = path.split('-')[0]
        path = str(tag) + '_' + path
        print(path)
        img = handle_from_url(url)
        cv2.imwrite('tem/' + path, img)

def read_path():
    path = '/srv/apps/fashionbase/infer/0515_test_img/'
    rs = os.listdir(path)
    for r in rs:
        if r == 'deal':
            continue
        source_path = path + r
        print(source_path)
        img = handle_from_path(source_path)
        store_path = '/srv/apps/fashionbase/infer/0515_test_img/deal/' + r
        cv2.imwrite(store_path, img)


if __name__ == '__main__':
    #read_excel()
    read_path()
