MarioPrzBasto commited on
Commit
a0787f2
·
verified ·
1 Parent(s): 35d85ac

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -18
main.py CHANGED
@@ -25,22 +25,20 @@ def orb_sim(img1, img2):
25
  return 0
26
  return len(similar_regions) / len(matches)
27
 
28
- async def load_image(image_path: str):
29
- """Carrega uma imagem a partir de um caminho de arquivo ou URL."""
30
- try:
31
- if image_path.startswith("http://") or image_path.startswith("https://"):
32
- async with httpx.AsyncClient() as client:
33
- response = await client.get(image_path)
34
- response.raise_for_status()
35
- image_bytes = np.frombuffer(response.content, np.uint8)
36
- img = cv2.imdecode(image_bytes, cv2.IMREAD_COLOR)
37
- return img
38
- else:
39
- img = cv2.imread(image_path)
40
- return img
41
- except Exception as e:
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 = await load_image(image_data.originSource)
55
- img2 = await load_image(image_data.source)
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: