Skip to content

Commit

Permalink
Automatically align images for OCR (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonchang authored Nov 9, 2024
1 parent fa89750 commit fddc049
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions frontend/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageToTextArgs, ImageToTextResponse, AlignImageArgs, AlignImageRespons

const apiUrl = import.meta.env.VITE_API_URL || "http://localhost:8000/"

export const AlignImage = async (args: AlignImageArgs): Promise<AlignImageResponse | null> => {
export const AlignImage = async (args: AlignImageArgs): Promise<AlignImageResponse> => {
const { sourceImage, templateImage } = args;
const form = new URLSearchParams({
source_image: sourceImage,
Expand All @@ -21,15 +21,16 @@ export const AlignImage = async (args: AlignImageArgs): Promise<AlignImageRespon
return await response.json() as AlignImageResponse;
} catch (error) {
console.error(error);
return null;
return {result: sourceImage};
}
}

export const ImageToText = async (args: ImageToTextArgs): Promise<ImageToTextResponse | null> => {

const { sourceImage, templateImage, fieldNames } = args;
const aligned_result = await AlignImage({sourceImage, templateImage});
const form = new URLSearchParams({
source_image: sourceImage,
source_image: aligned_result["result"],
segmentation_template: templateImage,
labels: JSON.stringify(fieldNames),
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/api/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ImageToTextResponse = {
};

export type AlignImageResponse = {
[key: string]: [string, number];
[key: string]: string;
};

export interface ResultItem {
Expand Down

0 comments on commit fddc049

Please sign in to comment.