Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -25,22 +25,20 @@ def orb_sim(img1, img2):
|
|
25 |
return 0
|
26 |
return len(similar_regions) / len(matches)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
print(f"Erro ao carregar a imagem {image_path}: {e}")
|
43 |
-
return None
|
44 |
|
45 |
app = FastAPI()
|
46 |
|
@@ -51,8 +49,8 @@ async def save(image_data: RequestModel):
|
|
51 |
os.makedirs(BASE_DIR, exist_ok=True)
|
52 |
filename = os.path.join(BASE_DIR, f"{image_data.originId}_{image_data.assetCode}.json")
|
53 |
|
54 |
-
img1 =
|
55 |
-
img2 =
|
56 |
|
57 |
similarity_orb = None
|
58 |
if img1 is not None and img2 is not None:
|
|
|
25 |
return 0
|
26 |
return len(similar_regions) / len(matches)
|
27 |
|
28 |
+
def load_image_url(source):
|
29 |
+
Image.MAX_IMAGE_PIXELS = None
|
30 |
+
|
31 |
+
if source.startswith('http'):
|
32 |
+
response = requests.get(source)
|
33 |
+
img = np.asarray(bytearray(response.content), dtype=np.uint8)
|
34 |
+
img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)
|
35 |
+
else:
|
36 |
+
img = base64.b64decode(source)
|
37 |
+
img = Image.open(BytesIO(img))
|
38 |
+
img = np.array(img)
|
39 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
40 |
+
|
41 |
+
return img
|
|
|
|
|
42 |
|
43 |
app = FastAPI()
|
44 |
|
|
|
49 |
os.makedirs(BASE_DIR, exist_ok=True)
|
50 |
filename = os.path.join(BASE_DIR, f"{image_data.originId}_{image_data.assetCode}.json")
|
51 |
|
52 |
+
img1 = load_image(image_data.originSource)
|
53 |
+
img2 = load_image(image_data.source)
|
54 |
|
55 |
similarity_orb = None
|
56 |
if img1 is not None and img2 is not None:
|