Revize 4cedc63b
Přidáno uživatelem smoldas15 před téměř 5 roky(ů)
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java | ||
---|---|---|
55 | 55 |
private static final int DEFAULT_LINE_FIELD_COUNT = 150; |
56 | 56 |
private static final int DEFAULT_WORD_FIELD_COUNT = 30; |
57 | 57 |
|
58 |
private static final int DEFAULT_WORD_HEIGHT = 30; |
|
59 |
|
|
58 | 60 |
private HttpSolrClient solrClientDocuments; |
59 | 61 |
private HttpSolrClient solrClientFiles; |
60 | 62 |
private List<String> fieldNamesDocumentCore = new ArrayList<>(); |
... | ... | |
300 | 302 |
Set<String> linesNames = linesAndWordsNames.stream().filter(name -> name.startsWith(PREFIX_TEXT_LINE)).collect(Collectors.toSet()); |
301 | 303 |
Set<String> wordNames = linesAndWordsNames.stream().filter(name -> name.startsWith(PREFIX_TEXT_WORD)).collect(Collectors.toSet()); |
302 | 304 |
|
305 |
//----- |
|
306 |
|
|
307 |
String imgFilename = (String) solrDocument.getFieldValue(FIELD_IMG_FILENAME); |
|
308 |
byte[] imageBytes = getImageFromFilesCore(imgFilename); |
|
309 |
|
|
310 |
BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(imageBytes))); |
|
311 |
Image cropImg = new Image(img); |
|
312 |
|
|
313 |
int y1 = textRegion.getRegionCoords().getPoints()[0].getY(); |
|
314 |
int y2 = textRegion.getRegionCoords().getPoints()[2].getY(); |
|
315 |
|
|
316 |
if (wordNames.size() == 1 || (wordNames.size() == 0 && linesNames.size() == 1)) { |
|
317 |
String coordsValue = ""; |
|
318 |
|
|
319 |
if (wordNames.size() == 1) { |
|
320 |
coordsValue = (String) solrDocument.getFieldValue(wordNames.stream().findFirst().get() + SUFFIX_COORDS); |
|
321 |
|
|
322 |
} else{ |
|
323 |
coordsValue = (String) solrDocument.getFieldValue(linesNames.stream().findFirst().get() + SUFFIX_COORDS); |
|
324 |
} |
|
325 |
Point[] arrPoints = Coords.parsePointString(coordsValue); |
|
326 |
int wordHeight = DEFAULT_WORD_HEIGHT; |
|
327 |
|
|
328 |
if (arrPoints.length == 4) { |
|
329 |
wordHeight = arrPoints[2].getY() - arrPoints[0].getY(); |
|
330 |
} |
|
331 |
|
|
332 |
if (y1 < (arrPoints[0].getY() - (2 * wordHeight))) { |
|
333 |
y1 = arrPoints[0].getY() - (2 * wordHeight); |
|
334 |
} |
|
335 |
|
|
336 |
if (y2 > (arrPoints[0].getY() + (3 * wordHeight))) { |
|
337 |
y2 = arrPoints[0].getY() + (3 * wordHeight); |
|
338 |
} |
|
339 |
} |
|
340 |
|
|
341 |
cropImg.crop(textRegion.getRegionCoords().getPoints()[0].getX(), y1, |
|
342 |
textRegion.getRegionCoords().getPoints()[1].getX() - textRegion.getRegionCoords().getPoints()[0].getX(), |
|
343 |
y2 - y1); |
|
344 |
|
|
345 |
cropImg.setOutputQuality(IMG_OUTPUT_QUALITY); |
|
346 |
|
|
347 |
imageBytes = cropImg.getByteArray(); |
|
348 |
imageBytes = Base64.getEncoder().encode(imageBytes); |
|
349 |
textRegion.setImageCut(new String(imageBytes)); |
|
350 |
|
|
351 |
//----- |
|
352 |
|
|
303 | 353 |
Map<String, TextLine> textLines = new HashMap<>(); |
304 | 354 |
for (String lineName: linesNames) { |
305 | 355 |
TextLine textLine = new TextLine(); |
... | ... | |
355 | 405 |
|
356 | 406 |
textRegion.setTextLines(textLines.values().toArray(new TextLine[0])); |
357 | 407 |
|
358 |
// cropping image |
|
359 |
String imgFilename = (String) solrDocument.getFieldValue(FIELD_IMG_FILENAME); |
|
360 |
byte[] imageBytes = getImageFromFilesCore(imgFilename); |
|
361 |
|
|
362 |
BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(imageBytes))); |
|
363 |
Image cropImg = new Image(img); |
|
364 |
cropImg.crop(textRegion.getRegionCoords().getPoints()[0].getX(),textRegion.getRegionCoords().getPoints()[0].getY(), |
|
365 |
textRegion.getRegionCoords().getPoints()[1].getX()-textRegion.getRegionCoords().getPoints()[0].getX(), |
|
366 |
textRegion.getRegionCoords().getPoints()[2].getY()-textRegion.getRegionCoords().getPoints()[0].getY()); |
|
367 |
|
|
368 |
cropImg.setOutputQuality(IMG_OUTPUT_QUALITY); |
|
369 |
|
|
370 |
imageBytes = cropImg.getByteArray(); |
|
371 |
imageBytes = Base64.getEncoder().encode(imageBytes); |
|
372 |
|
|
373 | 408 |
// recalculating Coords - during init for words and lines |
374 | 409 |
for (int k = 1; k<textRegion.getRegionCoords().getPoints().length; k++){ |
375 | 410 |
textRegion.getRegionCoords().getPoints()[k].setX(textRegion.getRegionCoords().getPoints()[k].getX() - textRegion.getRegionCoords().getPoints()[0].getX()); |
... | ... | |
378 | 413 |
textRegion.getRegionCoords().getPoints()[0].setX(0); |
379 | 414 |
textRegion.getRegionCoords().getPoints()[0].setY(0); |
380 | 415 |
|
381 |
textRegion.setImageCut(new String(imageBytes)); |
|
382 |
|
|
383 | 416 |
// image size |
384 | 417 |
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(imageBytes))); |
385 | 418 |
DocumentSize documentSize = new DocumentSize(image.getHeight(), image.getWidth()); |
Také k dispozici: Unified diff
Re #7912: Ořezávání obrázků
- úprava stávajícího ořezávání obrázků
- přidání rozhodování na základě počtu nalezených výrazů