Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit b2d9f51

Browse files
author
superdev808
authored
feat: DEV-1656: Fix OCR Focus Text (#507)
* Fix OCR Focus Text * Fix comment: Add new example for OCR Template * Fix comment * OCR Focus Text Issue fix
1 parent 9f7d62a commit b2d9f51

File tree

7 files changed

+210
-3
lines changed

7 files changed

+210
-3
lines changed

examples/image_ocr/START.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
# Image object detection
3+
4+
![Image Object Detection](/images/screenshots/image_bbox.png "Image Object Detection")
5+
6+
# Install
7+
8+
## Linux & Ubuntu guide
9+
10+
Install python and virtualenv
11+
12+
```bash
13+
# install python and virtualenv
14+
apt install python3.6
15+
pip3 install virtualenv
16+
17+
# setup python virtual environment
18+
virtualenv -p python3 env3
19+
source env3/bin/activate
20+
21+
# install requirements
22+
cd backend
23+
pip install -r requirements.txt
24+
```
25+
26+
# Start
27+
28+
Image bounding box labeling
29+
30+
```bash
31+
python server.py -c config.json -l ../examples/image_bbox/config.xml -i ../examples/image_bbox/tasks.json -o output
32+
```
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"annotations": [
3+
{
4+
"id": "1001",
5+
"lead_time": 15.053,
6+
"result": [
7+
{
8+
"from_name": "tag",
9+
"id": "Dx_aB91ISN",
10+
"source": "$image",
11+
"to_name": "img",
12+
"type": "rectanglelabels",
13+
"value": {
14+
"height": 10.458911419423693,
15+
"rectanglelabels": [
16+
"Moonwalker"
17+
],
18+
"rotation": 0,
19+
"width": 12.4,
20+
"x": 50.8,
21+
"y": 5.869797225186766
22+
}
23+
}
24+
]
25+
}
26+
],
27+
"data": {
28+
"image": "https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg"
29+
},
30+
"id": 1,
31+
"predictions": [
32+
{
33+
"created_ago": "3 hours",
34+
"model_version": "model 1",
35+
"result": [
36+
{
37+
"from_name": "tag",
38+
"id": "t5sp3TyXPo",
39+
"source": "$image",
40+
"to_name": "img",
41+
"type": "rectanglelabels",
42+
"value": {
43+
"height": 11.612284069097889,
44+
"rectanglelabels": [
45+
"Moonwalker"
46+
],
47+
"rotation": 0,
48+
"width": 39.6,
49+
"x": 13.2,
50+
"y": 34.702495201535505
51+
}
52+
}
53+
]
54+
},
55+
{
56+
"created_ago": "4 hours",
57+
"model_version": "model 2",
58+
"result": [
59+
{
60+
"from_name": "tag",
61+
"id": "t5sp3TyXPo",
62+
"source": "$image",
63+
"to_name": "img",
64+
"type": "rectanglelabels",
65+
"value": {
66+
"height": 33.61228406909789,
67+
"rectanglelabels": [
68+
"Moonwalker"
69+
],
70+
"rotation": 0,
71+
"width": 39.6,
72+
"x": 13.2,
73+
"y": 54.702495201535505
74+
}
75+
}
76+
]
77+
}
78+
]
79+
}

examples/image_ocr/config.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<View>
2+
<Image name="image" value="$image"/>
3+
<Labels name="label" toName="image">
4+
<Label value="Text" background="green"/>
5+
<Label value="Handwriting" background="blue"/>
6+
</Labels>
7+
<Rectangle name="bbox" toName="image" strokeWidth="3"/>
8+
<Polygon name="poly" toName="image" strokeWidth="3"/>
9+
<TextArea name="transcription" toName="image"
10+
editable="true"
11+
perRegion="true"
12+
required="true"
13+
maxSubmissions="1"
14+
rows="5"
15+
placeholder="Recognized Text"
16+
displayMode="region-list"
17+
/>
18+
</View>

examples/image_ocr/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import config from "./config.xml";
2+
import tasks from "./tasks.json";
3+
import annotation from "./annotations/1.json";
4+
5+
export const ImageOCR = { config, tasks, annotation };

examples/image_ocr/tasks.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[
2+
{
3+
"data": {
4+
"image": "https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg"
5+
},
6+
"predictions": [
7+
{
8+
"model_version": "model 1",
9+
"created_ago": "3 hours",
10+
"result": [
11+
{
12+
"from_name": "tag",
13+
"id": "t5sp3TyXPo",
14+
"source": "$image",
15+
"to_name": "img",
16+
"type": "rectanglelabels",
17+
"value": {
18+
"height": 11.612284069097889,
19+
"rectanglelabels": [
20+
"Moonwalker"
21+
],
22+
"rotation": 0,
23+
"width": 39.6,
24+
"x": 13.2,
25+
"y": 34.702495201535505
26+
}
27+
}
28+
]
29+
},
30+
{
31+
"model_version": "model 2",
32+
"created_ago": "4 hours",
33+
"result": [
34+
{
35+
"from_name": "tag",
36+
"id": "t5sp3TyXPo",
37+
"source": "$image",
38+
"to_name": "img",
39+
"type": "rectanglelabels",
40+
"value": {
41+
"height": 33.61228406909789,
42+
"rectanglelabels": [
43+
"Moonwalker"
44+
],
45+
"rotation": 0,
46+
"width": 39.6,
47+
"x": 13.2,
48+
"y": 54.702495201535505
49+
}
50+
}
51+
]
52+
}
53+
]
54+
},
55+
{
56+
"data": {
57+
"image": "https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/history-in-hd-e5eDHbmHprg-unsplash.jpg"
58+
}
59+
},
60+
{
61+
"data": {
62+
"image": "https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/soroush-karimi-crjPrExvShc-unsplash.jpg"
63+
}
64+
}
65+
]

src/env/development.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { ImageBboxLarge } from "../examples/image_bbox_large";
3232
import { ImageKeyPoint } from "../examples/image_keypoints";
3333
import { ImageMultilabel } from "../examples/image_multilabel";
3434
import { ImageEllipselabels } from "../examples/image_ellipses";
35+
import { ImageOCR } from "../examples/image_ocr";
3536
import { ImagePolygons } from "../examples/image_polygons";
3637
import { ImageSegmentation } from "../examples/image_segmentation";
3738
import { ImageTools } from "../examples/image_tools";
@@ -65,7 +66,7 @@ import { TimeSeriesSingle } from "../examples/timeseries_single";
6566
*/
6667
// import { AllTypes } from "../examples/all_types";
6768

68-
const data = AudioRegions;
69+
const data = ImageOCR;
6970

7071
function getData(task) {
7172
if (task && task.data) {

src/tags/control/TextArea/TextArea.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ const HtxTextAreaRegionView = observer(({ item, area, collapsed, setCollapsed })
483483

484484
item.setValue(value);
485485
},
486-
onFocus: () => {
486+
onFocus: (ev) => {
487+
ev.stopPropagation();
488+
ev.preventDefault();
487489
if (!area.isSelected) {
488490
area.annotation.selectArea(area);
489491
}
@@ -528,8 +530,13 @@ const HtxTextAreaRegionView = observer(({ item, area, collapsed, setCollapsed })
528530
}
529531
return false;
530532
}}
533+
onClick={(e) => {
534+
e.stopPropagation();
535+
}}
531536
>
532-
<Elem name="input" tag={isTextArea ? TextArea : Input} {...props} />
537+
<Elem name="input" tag={isTextArea ? TextArea : Input} {...props} onClick={(e) => {
538+
e.stopPropagation();
539+
}} />
533540
</Elem>
534541
)}
535542
</Block>

0 commit comments

Comments
 (0)