-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathimage_recomend.py
executable file
·63 lines (43 loc) · 1.43 KB
/
image_recomend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
from flask import request
import io
import base64
import numpy as np
import re
# image preproccessing
from pyimagesearch.colordescriptor import ColorDescriptor
from pyimagesearch.searcher import Searcher
import argparse
import cv2
# Firebase
class Images(object):
def __init__(self):
self.APP_ROOT = os.path.dirname(os.path.abspath(__file__))
def Upload(self):
target = os.path.join(self.APP_ROOT, 'static/images')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
print(request.files.getlist("file"))
for file in request.files.getlist("file"):
print('come here')
print(file)
filename = file.filename
print(filename)
destination = "/".join([target, filename])
print(destination)
file.save(destination)
return destination
def predict(self,location):
# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))
print(location)
query = cv2.imread(location)
features = cd.describe(query)
searcher = Searcher("index.csv")
results = searcher.search(features)
final_res = []
for (score, resultID) in results:
final_res.append(resultID)
print(score,resultID)
return final_res[0]