-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbaa554
commit c4cc6ab
Showing
6 changed files
with
206 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
from typing import List | ||
from pydantic import BaseModel | ||
import base64 | ||
import io | ||
import numpy as np | ||
from fastapi.exceptions import HTTPException | ||
from PIL import Image | ||
from pathlib import Path | ||
|
||
sys.path.append(str(Path(__file__).parents[1])) | ||
from hloc import logger | ||
|
||
|
||
class ImagesInput(BaseModel): | ||
data: List[str] = [] | ||
max_keypoints: List[int] = [] | ||
timestamps: List[str] = [] | ||
grayscale: bool = False | ||
image_hw: List[List[int]] = [[], []] | ||
feature_type: int = 0 | ||
rotates: List[float] = [] | ||
scales: List[float] = [] | ||
reference_points: List[List[float]] = [] | ||
binarize: bool = False | ||
|
||
|
||
def decode_base64_to_image(encoding): | ||
if encoding.startswith("data:image/"): | ||
encoding = encoding.split(";")[1].split(",")[1] | ||
try: | ||
image = Image.open(io.BytesIO(base64.b64decode(encoding))) | ||
return image | ||
except Exception as e: | ||
logger.warning(f"API cannot decode image: {e}") | ||
raise HTTPException( | ||
status_code=500, detail="Invalid encoded image" | ||
) from e | ||
|
||
|
||
def to_base64_nparray(encoding: str) -> np.ndarray: | ||
return np.array(decode_base64_to_image(encoding)).astype("uint8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file was generated using the `serve build` command on Ray v2.38.0. | ||
|
||
proxy_location: EveryNode | ||
http_options: | ||
host: 0.0.0.0 | ||
port: 8000 | ||
|
||
grpc_options: | ||
port: 9000 | ||
grpc_servicer_functions: [] | ||
|
||
logging_config: | ||
encoding: TEXT | ||
log_level: INFO | ||
logs_dir: null | ||
enable_access_log: true | ||
|
||
applications: | ||
- name: app1 | ||
route_prefix: / | ||
import_path: api.server:service | ||
runtime_env: {} | ||
deployments: | ||
- name: ImageMatchingService | ||
num_replicas: 4 | ||
ray_actor_options: | ||
num_cpus: 2.0 | ||
num_gpus: 1.0 | ||
|
||
api: | ||
feature: | ||
output: feats-superpoint-n4096-rmax1600 | ||
model: | ||
name: superpoint | ||
nms_radius: 3 | ||
max_keypoints: 4096 | ||
keypoint_threshold: 0.005 | ||
preprocessing: | ||
grayscale: True | ||
force_resize: True | ||
resize_max: 1600 | ||
width: 640 | ||
height: 480 | ||
dfactor: 8 | ||
matcher: | ||
output: matches-NN-mutual | ||
model: | ||
name: nearest_neighbor | ||
do_mutual_check: True | ||
match_threshold: 0.2 | ||
dense: False |
Oops, something went wrong.