pixel_sampling.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:kaggle-yelp-restaurant-photo-classification 作者: u1234x1234 项目源码 文件源码
def extract_lab_histogram(mode, clusters):

    nn = neighbors.NearestNeighbors(n_neighbors=1)
    nn.fit(clusters)
    out_filename = mode + '_color'    
    try:
        os.remove(out_filename)
    except:
        pass
    out = open(out_filename, 'ab')
    cnt = 0    
    with open(mode + '_list') as f:
        for line in f:
            line = line[:-1]
            image = cv2.imread(line)
            image = cv2.resize(image, (100, 100))
            image = cv2.cvtColor(image, cv2.COLOR_BGR2Lab)
            points = image.reshape((-1, 3))
            cn = nn.kneighbors(points)
            hist = np.histogram(cn[1], bins=50, range=(1, 50))[0]
            hist.tofile(out)            
            cnt = cnt + 1
            if cnt % 1000 == 0:
                print(cnt)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号