Revize 7b710808
Přidáno uživatelem Ondřej Váně před téměř 5 roky(ů)
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java | ||
---|---|---|
339 | 339 |
DocumentSize documentSize = new DocumentSize(image.getHeight(), image.getWidth()); |
340 | 340 |
textRegion.setDocumentSize(documentSize); |
341 | 341 |
|
342 |
// generate random string id for response of given length |
|
343 |
textRegion.setRandomId(Utils.generateRandomStringId(10)); |
|
344 |
|
|
342 | 345 |
textRegions.add(textRegion); |
343 | 346 |
} |
344 | 347 |
|
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/Utils.java | ||
---|---|---|
1 |
package cz.zcu.kiv.aswi.fulltextsearch; |
|
2 |
|
|
3 |
import java.nio.charset.StandardCharsets; |
|
4 |
import java.util.Random; |
|
5 |
|
|
6 |
public class Utils { |
|
7 |
|
|
8 |
public static String generateRandomStringId(int length) { |
|
9 |
|
|
10 |
// length is bounded by 256 Character |
|
11 |
byte[] array = new byte[256]; |
|
12 |
new Random().nextBytes(array); |
|
13 |
|
|
14 |
String randomString |
|
15 |
= new String(array, StandardCharsets.UTF_8); |
|
16 |
|
|
17 |
// Create a StringBuffer to store the result |
|
18 |
StringBuffer r = new StringBuffer(); |
|
19 |
|
|
20 |
for (int k = 0; k < randomString.length(); k++) { |
|
21 |
|
|
22 |
char ch = randomString.charAt(k); |
|
23 |
|
|
24 |
if (((ch >= 'a' && ch <= 'z') |
|
25 |
|| (ch >= 'A' && ch <= 'Z') |
|
26 |
|| (ch >= '0' && ch <= '9')) |
|
27 |
&& (length > 0)) { |
|
28 |
|
|
29 |
r.append(ch); |
|
30 |
length--; |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
return r.toString(); |
|
35 |
} |
|
36 |
} |
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/document/TextRegion.java | ||
---|---|---|
15 | 15 |
private TextLine[] textLines; |
16 | 16 |
private String documentName; |
17 | 17 |
private DocumentSize documentSize; |
18 |
private String randomId; |
|
18 | 19 |
|
19 | 20 |
@JsonIgnore |
20 | 21 |
private TextEquiv textEquiv; |
... | ... | |
77 | 78 |
public void setDocumentSize(DocumentSize documentSize) { |
78 | 79 |
this.documentSize = documentSize; |
79 | 80 |
} |
81 |
|
|
82 |
public String getRandomId() { |
|
83 |
return randomId; |
|
84 |
} |
|
85 |
|
|
86 |
public void setRandomId(String randomId) { |
|
87 |
this.randomId = randomId; |
|
88 |
} |
|
80 | 89 |
} |
fe/fulltextsearch/src/app/components/pages/search/search-paginator/search-paginator.component.html | ||
---|---|---|
8 | 8 |
{{row.documentName}} |
9 | 9 |
</div> |
10 | 10 |
<div class="row image-div"> |
11 |
<img id="{{row.documentName + 'Img'}}"
|
|
11 |
<img id="{{row.randomId + 'Img'}}"
|
|
12 | 12 |
class="image" src="data:image/jpg;base64,{{row.imageCut}}" |
13 |
(load)="draw(row,row.documentName + 'Img' , row.documentName + 'Canvas' )"/>
|
|
14 |
<canvas id="{{row.documentName + 'Canvas'}}" style="position: absolute;" title="TEST">
|
|
13 |
(load)="draw(row,row.randomId + 'Img' , row.randomId + 'Canvas' )"/>
|
|
14 |
<canvas id="{{row.randomId + 'Canvas'}}" style="position: absolute;" title="Result">
|
|
15 | 15 |
Your browser does not support the HTML5 canvas tag. |
16 | 16 |
</canvas> |
17 | 17 |
</div> |
fe/fulltextsearch/src/app/model/parts/TextRegion.ts | ||
---|---|---|
1 | 1 |
import { Coords } from './Coords'; |
2 | 2 |
import { TextLine } from './TextLine'; |
3 |
import {DocumentSize} from './DocumentSize';
|
|
3 |
import { DocumentSize } from './DocumentSize';
|
|
4 | 4 |
|
5 | 5 |
export class TextRegion { |
6 | 6 |
public imageCut: string; |
... | ... | |
9 | 9 |
public textLines: TextLine[]; |
10 | 10 |
public documentName: string; |
11 | 11 |
public documentSize: DocumentSize; |
12 |
public randomId: string; |
|
12 | 13 |
} |
fe/fulltextsearch/src/app/services/drawer/drawer.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core';
|
|
1 |
import {Injectable} from '@angular/core';
|
|
2 | 2 |
import {LoggerService} from '../logger/logger.service'; |
3 | 3 |
import {TextRegion} from '../../model/parts/TextRegion'; |
4 | 4 |
import {Point} from '../../model/parts/Point'; |
5 | 5 |
import Utils from '../../../Utils'; |
6 |
import {DocumentSize} from '../../model/parts/DocumentSize'; |
|
6 | 7 |
|
7 | 8 |
@Injectable({ |
8 | 9 |
providedIn: 'root' |
9 | 10 |
}) |
10 | 11 |
export class DrawerService { |
11 | 12 |
|
13 |
resizeRation: number = null; |
|
14 |
|
|
12 | 15 |
constructor(private LOGGER: LoggerService) { } |
13 | 16 |
|
14 | 17 |
public drawResult(textRegion: TextRegion, imageId: string, canvasId: string) { |
15 |
const canvasContext = this.initCanvas(imageId, canvasId); |
|
16 |
|
|
17 |
if (textRegion !== null) { |
|
18 |
if (Utils.isIterable(textRegion.textLines) && textRegion.textLines.length !== 0) { |
|
19 |
for (const textLine of textRegion.textLines) { |
|
20 |
if (Utils.isIterable(textLine.textWords) && textLine.textWords.length !== 0) { |
|
21 |
for (const textWord of textLine.textWords) { |
|
22 |
if (textWord !== null) { |
|
23 |
// print words |
|
24 |
this.draw(textWord.wordCoords.points, canvasContext); |
|
25 |
this.LOGGER.info('printing words'); |
|
26 |
} |
|
18 |
const canvasContext = this.initCanvas(imageId, canvasId, textRegion.documentSize); |
|
19 |
if (Utils.isIterable(textRegion.textLines) && textRegion.textLines.length !== 0) { |
|
20 |
for (const textLine of textRegion.textLines) { |
|
21 |
if (Utils.isIterable(textLine.textWords) && textLine.textWords.length !== 0) { |
|
22 |
for (const textWord of textLine.textWords) { |
|
23 |
if (textWord !== null) { |
|
24 |
// print words |
|
25 |
this.draw(textWord.wordCoords.points, canvasContext); |
|
26 |
this.LOGGER.info('printing words'); |
|
27 | 27 |
} |
28 |
return; |
|
29 |
} else { |
|
30 |
// print lines |
|
31 |
this.draw(textLine.lineCoords.points, canvasContext); |
|
32 |
this.LOGGER.info('Print lines'); |
|
33 | 28 |
} |
29 |
return; |
|
30 |
} else { |
|
31 |
// print lines |
|
32 |
this.draw(textLine.lineCoords.points, canvasContext); |
|
33 |
this.LOGGER.info('Print lines'); |
|
34 | 34 |
} |
35 |
return; |
|
36 |
} else { |
|
37 |
// all region |
|
38 |
this.draw(textRegion.regionCoords.points, canvasContext); |
|
39 |
this.LOGGER.info('Print region'); |
|
40 | 35 |
} |
36 |
return; |
|
41 | 37 |
} else { |
42 |
// all document
|
|
43 |
// TODO : obarvit celý výřez
|
|
44 |
this.LOGGER.warn('Print all document');
|
|
38 |
// all region
|
|
39 |
this.draw(textRegion.regionCoords.points, canvasContext);
|
|
40 |
this.LOGGER.info('Print region');
|
|
45 | 41 |
} |
46 | 42 |
} |
47 | 43 |
|
48 |
private initCanvas(imageId: string, canvasId: string) { |
|
44 |
private initCanvas(imageId: string, canvasId: string, originalImageSize: DocumentSize) {
|
|
49 | 45 |
const img = document.getElementById(imageId); |
50 | 46 |
const canvasElement = document.getElementById(canvasId); |
51 | 47 |
const canvas = <HTMLCanvasElement> document.getElementById(canvasId); |
... | ... | |
60 | 56 |
ctx.canvas.width = img.offsetWidth; |
61 | 57 |
ctx.canvas.height = img.offsetHeight; |
62 | 58 |
|
59 |
this.countRatio(originalImageSize, new DocumentSize(img.offsetHeight, img.offsetWidth)); |
|
60 |
|
|
63 | 61 |
return ctx; |
64 | 62 |
} |
65 | 63 |
|
... | ... | |
69 | 67 |
|
70 | 68 |
for (const point of points) { |
71 | 69 |
if (firstPoint) { |
72 |
context.moveTo(point.x / 1.676, point.y / 1.676);
|
|
70 |
context.moveTo(point.x / this.resizeRation, point.y / this.resizeRation);
|
|
73 | 71 |
firstPoint = false; |
74 | 72 |
} else { |
75 |
context.lineTo(point.x / 1.676, point.y / 1.676);
|
|
73 |
context.lineTo(point.x / this.resizeRation, point.y / this.resizeRation);
|
|
76 | 74 |
} |
77 | 75 |
} |
78 | 76 |
context.closePath(); |
... | ... | |
83 | 81 |
context.fill(); |
84 | 82 |
context.stroke(); |
85 | 83 |
} |
84 |
|
|
85 |
private countRatio(originalSize: DocumentSize, shownSize: DocumentSize) { |
|
86 |
this.resizeRation = originalSize.width / shownSize.width; |
|
87 |
} |
|
86 | 88 |
} |
Také k dispozici: Unified diff
Re #7820: Vykreslení rámečku do výřezu dokumentu
- posunutí koordinátů dle výpočtu (originální/zobrazená velikost)
- genererování náhodného id na BE
- přijmutí náhodného id na FE a nastaveno jako id pro výsledky