-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat: show OCR bounding box #23717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: show OCR bounding box #23717
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8b667c
feat: ocr bounding box
alextran1502 fac6539
bounding boxes
alextran1502 4eaa822
pr feedback
alextran1502 12c88da
Merge branch 'main' into ocr-bounding-box
alextran1502 23b1ab0
pr feedback
alextran1502 a52a410
allow copy across text boxes
alextran1502 4839a17
pr feedback
alextran1502 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
web/src/lib/components/asset-viewer/ocr-bounding-box.svelte
alextran1502 marked this conversation as resolved.
Show resolved
Hide resolved
alextran1502 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,36 @@ | ||
| <script lang="ts"> | ||
| import type { OcrBox } from '$lib/utils/ocr-utils'; | ||
| import { calculateBoundingBoxDimensions } from '$lib/utils/ocr-utils'; | ||
|
|
||
| type Props = { | ||
| ocrBox: OcrBox; | ||
| }; | ||
|
|
||
| let { ocrBox }: Props = $props(); | ||
|
|
||
| const dimensions = $derived(calculateBoundingBoxDimensions(ocrBox.points)); | ||
|
|
||
| const transform = $derived( | ||
| `translate(${dimensions.minX}px, ${dimensions.minY}px) rotate(${dimensions.rotation}deg) skew(${dimensions.skewX}deg, ${dimensions.skewY}deg)`, | ||
| ); | ||
|
|
||
| const transformOrigin = $derived( | ||
| `${dimensions.centerX - dimensions.minX}px ${dimensions.centerY - dimensions.minY}px`, | ||
| ); | ||
| </script> | ||
|
|
||
| <div class="absolute group left-0 top-0 pointer-events-none"> | ||
| <!-- Bounding box with CSS transforms --> | ||
| <div | ||
| class="absolute border-2 border-blue-500 bg-blue-500/10 cursor-pointer pointer-events-auto transition-all group-hover:bg-blue-500/30 group-hover:border-blue-600 group-hover:border-[3px]" | ||
| style="width: {dimensions.width}px; height: {dimensions.height}px; transform: {transform}; transform-origin: {transformOrigin};" | ||
| ></div> | ||
|
|
||
| <!-- Text overlay - always rendered but invisible, allows text selection and copy --> | ||
| <div | ||
| class="absolute flex items-center justify-center text-transparent text-sm px-2 py-1 pointer-events-auto cursor-text whitespace-pre-wrap wrap-break-word select-text group-hover:text-white group-hover:bg-black/75 group-hover:z-10" | ||
| style="width: {dimensions.width}px; height: {dimensions.height}px; transform: {transform}; transform-origin: {transformOrigin};" | ||
| > | ||
| {ocrBox.text} | ||
| </div> | ||
| </div> |
This file contains hidden or 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,17 @@ | ||
| <script lang="ts"> | ||
| import { ocrManager } from '$lib/stores/ocr.svelte'; | ||
| import { IconButton } from '@immich/ui'; | ||
| import { mdiTextRecognition } from '@mdi/js'; | ||
| import { t } from 'svelte-i18n'; | ||
| </script> | ||
|
|
||
| <IconButton | ||
| title={ocrManager.showOverlay ? $t('hide_text_recognition') : $t('show_text_recognition')} | ||
| icon={mdiTextRecognition} | ||
| class={"dark {ocrStore.showOverlay ? 'bg-immich-primary text-white dark' : 'dark'}"} | ||
| color="secondary" | ||
| variant="ghost" | ||
| shape="round" | ||
| aria-label={$t('text_recognition')} | ||
| onclick={() => ocrManager.toggleOcrBoundingBox()} | ||
| /> |
This file contains hidden or 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 hidden or 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,44 @@ | ||
| import { getAssetOcr } from '@immich/sdk'; | ||
|
|
||
| export type OcrBoundingBox = { | ||
| id: string; | ||
| assetId: string; | ||
| x1: number; | ||
| y1: number; | ||
| x2: number; | ||
| y2: number; | ||
| x3: number; | ||
| y3: number; | ||
| x4: number; | ||
| y4: number; | ||
| boxScore: number; | ||
| textScore: number; | ||
| text: string; | ||
| }; | ||
|
|
||
| class OcrManager { | ||
| #data = $state<OcrBoundingBox[]>([]); | ||
| showOverlay = $state(false); | ||
| hasOcrData = $state(false); | ||
|
|
||
| get data() { | ||
| return this.#data; | ||
| } | ||
|
|
||
| async getAssetOcr(id: string) { | ||
| this.#data = await getAssetOcr({ id }); | ||
| this.hasOcrData = this.#data.length > 0; | ||
| } | ||
|
|
||
| clear() { | ||
| this.#data = []; | ||
| this.showOverlay = false; | ||
| this.hasOcrData = false; | ||
| } | ||
|
|
||
| toggleOcrBoundingBox() { | ||
| this.showOverlay = !this.showOverlay; | ||
| } | ||
| } | ||
|
|
||
| export const ocrManager = new OcrManager(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.