コード例 #1
0
ファイル: app.py プロジェクト: HauVuTri/ImageProcessing
def search():

    # Dữ liệu đầu vào
    file = request.files['file']
    file.save('./' + file.filename)

    features = mongo.db.features
    # Đọc ảnh input
    image = cv2.imread('./' + file.filename)

    color_feature = Descriptor.color_history(image, 8)
    lpb_feature = Descriptor.lpb_history(image, 24, 8)
    hog_feature = Descriptor.hog(image, 10, 2, 9)

    feature = np.hstack([color_feature, lpb_feature, hog_feature])
    db_features = features.find()
    results_euclidean = {}
    results_cosine = {}
    for db_feature in db_features:
        dist_euclidean = euclidean(np.asarray(db_feature['feature']), feature)
        results_euclidean[db_feature['path']] = dist_euclidean
        dist_cosine = cosine(np.asarray(db_feature['feature']), feature)
        results_cosine[db_feature['path']] = dist_cosine

    results_euclidean = sorted([(d, n) for n, d in results_euclidean.items()])
    results_cosine = sorted([(d, n) for n, d in results_cosine.items()])
    return jsonify({
        'result_euclidean': results_euclidean,
        'result_cosine': results_cosine
    })
コード例 #2
0
ファイル: app.py プロジェクト: HauVuTri/ImageProcessing
def process():
    dirs = os.listdir(path)
    features = mongo.db.features
    for file in dirs:
        # đọc từng file
        image = cv2.imread(path + '/' + file)
        #    Vẽ sơ đồ histogram của 3 đặc trưng :
        # đặc trưng màu sắc,
        color_feature = Descriptor.color_history(image, 8)
        # đặc trưng kết cấu ảnh(lpb),
        lpb_feature = Descriptor.lpb_history(image, 24, 8)
        # đặc trưng HOG
        hog_feature = Descriptor.hog(image, 10, 2, 9)

        feature = list(np.hstack([color_feature, lpb_feature, hog_feature]))
        id = features.insert_one({
            'path': path + '/' + file,
            'feature': feature
        })

    return 'done'