Skip to content

Commit

Permalink
version/0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnth committed May 27, 2020
2 parents 229b37e + e44108c commit af161d4
Show file tree
Hide file tree
Showing 36 changed files with 2,264 additions and 1,666 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ Go to `localhost:8080/Larex`.
You can add your own books by copying them to src/webapp/resources/books

(Or an alternative direction set in the [config file](https://github.com/OCR4all/LAREX/blob/master/src/main/webapp/WEB-INF/larex.config). See section [*Configuration*](#configuration) for more information).
.

Book directories must have the following structure:
```
bookDir/
├── <book_name>/
│ ├── <page_name>.png
│ └── <page_name>.xml
└── <book2_name>/
└── …
```
### More information
Detailed information about the usage of LAREX can be found in the OCR4all [getting started](https://github.com/OCR4all/getting_started) guides.

Expand Down Expand Up @@ -182,6 +191,19 @@ The easiest direct request would be via a html form with the values *bookpath*,
</form>
```

### OCR4all UI mode ###
This setting enables or disables OCR4all UI mode.

`<value>=[enable|disable]`

This setting allows displaying and/or hiding certain UI elements when LAREX is used in combination with OCR4all.

`enable`: enable OCR4all UI mode

`disable`: disable OCR4all UI mode [default]

e.g. ocr4all:enable

## Related Publications:
Reul, Christian; Springmann, Uwe; Puppe, Frank: LAREX – A semi-automatic open-source Tool for Layout Analysis and Region Extraction on Early Printed Books. In Proceedings of the 2nd International Conference on Digital Access to Textual Cultural Heritage (2017). [ACM](https://dl.acm.org/citation.cfm?id=3078097). Draft available at [arXiv](https://arxiv.org/abs/1701.07396).

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.uniwue</groupId>
<artifactId>Larex</artifactId>
<version>0.2.3</version>
<version>0.3.0</version>
<packaging>war</packaging>

<name>Larex</name>
Expand Down
72 changes: 71 additions & 1 deletion scss/viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ body{
cursor: pointer;
}
#menu{
z-index:2;
z-index:3;
.menuIcon{
width: 40px;
height: 40px;
Expand Down Expand Up @@ -407,6 +407,36 @@ body{
}
}

.menuPageSelector{
.caret{
z-index: 3;
color: $color1;
pointer-events:none;
margin-right: 2px;
}
input {
height: 23px !important;
width: 100px !important;
background-color: $color4 !important;
color: $color1 !important;
padding: 0px 0px 0px 0px !important;
margin: 0px !important;
font-size: 14px !important;
text-indent: 34%;
}
ul {
li {
span{
color: $color1;
&:hover{
background-color: $color3;
color: $color2;
}
}
}
}
}

.invert {
color: $color2 !important;
background-color: $color3 !important;
Expand Down Expand Up @@ -681,6 +711,20 @@ body{
}
}

#textMode-options{
label{
margin: 10px 10px 20px 20px;
color: black;
}
}

.pred-text{
display: none;
font-size: 20px;
margin-top: 0;
margin-bottom: 0;
}

#textline-content{
z-index: 1;
position: absolute;
Expand Down Expand Up @@ -722,4 +766,30 @@ body{
bottom:-100%;
min-width:30px;
}
}

#vk-preset-modal {
width: 35%;
}

#batchSegmentConfirmationModal{
top: 33% !important;
width: 45%;
}

.collapsible-body-batch{
background-color: white;
padding: 10px 0 10px 20px;
}

#batchRunning{
display: none;
}

label{
color: black !important;
}

#batch-segmentation-progress{
display: none;
}
Binary file modified src/lib/repository/org/primaresearch/Dla/1.4.02/Dla-1.4.02.jar
Binary file not shown.
Binary file modified src/lib/repository/org/primaresearch/Io/1.4.02/Io-1.4.02.jar
Binary file not shown.
8 changes: 6 additions & 2 deletions src/main/java/de/uniwue/algorithm/segmentation/Segmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Collection<RegionSegment> segment(final Mat original, Parameters p

// detect and classify text regions
Collection<MatOfPoint> texts = detectText(binary, regions, existingGeometry, parameters.getTextDilationX(),
parameters.getTextDilationY(), scaleFactor);
parameters.getTextDilationY(), scaleFactor, images);

// classify
results.addAll(RegionClassifier.classifyRegions(regions, texts, binary.size()));
Expand Down Expand Up @@ -137,7 +137,7 @@ public static Collection<RegionSegment> segment(final Mat original, Parameters p
* @return
*/
private static Collection<MatOfPoint> detectText(final Mat binary, Collection<Region> regions, ExistingGeometry existingGeometry,
int textdilationX, int textdilationY, double scaleFactor) {
int textdilationX, int textdilationY, double scaleFactor, Collection<MatOfPoint> images) {
Mat dilate = new Mat();

if (textdilationX == 0 || textdilationY == 0) {
Expand All @@ -146,6 +146,10 @@ private static Collection<MatOfPoint> detectText(final Mat binary, Collection<Re
dilate = ImageProcessor.dilate(binary, new Size(textdilationX, textdilationY));
}

for (final MatOfPoint image : images) {
Imgproc.fillConvexPoly(dilate, image, new Scalar(0));
}

// draw user defined lines
final Mat workImage = existingGeometry.drawIntoImage(dilate, scaleFactor);
MemoryCleaner.clean(dilate);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.uniwue.web.communication;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.uniwue.web.facade.segmentation.SegmentationSettings;
import de.uniwue.web.model.PageAnnotations;

import java.util.List;

/**
* Communication object for the gui to request the segmentation of different
* pages. Contains the segmentation settings and a list of page numbers to
* segment.
*
*/
public class BatchSegmentationRequest {

@JsonProperty("settings")
private SegmentationSettings settings;
@JsonProperty("pages")
private List<Integer> pages;
@JsonProperty("save")
private boolean save;
@JsonProperty("bookid")
private Integer bookid;
@JsonProperty("version")
private String version;

@JsonCreator
public BatchSegmentationRequest(@JsonProperty("settings") SegmentationSettings settings,
@JsonProperty("pages") List<Integer> pages,
@JsonProperty("save") boolean save,
@JsonProperty("bookid") Integer bookid,
@JsonProperty("version") String version) {
this.pages = pages;
this.settings = settings;
this.save = save;
this.bookid = bookid;
this.version = version;
}

public List<Integer> getPages() {
return pages;
}

public SegmentationSettings getSettings() {
return settings;
}

public boolean getSave() { return save; }

public Integer getBookid() {
return bookid;
}

public String getVersion() {
return version;
}

}
33 changes: 33 additions & 0 deletions src/main/java/de/uniwue/web/controller/ConfigController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.uniwue.web.controller;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import de.uniwue.web.config.LarexConfiguration;
import de.uniwue.web.io.FilePathManager;

@Controller
@Scope("request")
public class ConfigController {
@Autowired
private FilePathManager fileManager;
@Autowired
private LarexConfiguration config;

/**
* Returns whether LAREX is configured to be used in conjunction with OCR4all or not.
*/
@RequestMapping(value = "config/ocr4all", method = RequestMethod.POST, headers = "Accept=*/*",
produces = "application/json")
public @ResponseBody Boolean isOCR4allMode() {
config.read(new File(fileManager.getConfigurationFile()));
String ocr4allMode = config.getSetting("ocr4all");
return ocr4allMode.equals("enable");
}
}
32 changes: 32 additions & 0 deletions src/main/java/de/uniwue/web/controller/DataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,36 @@ private void init() {
}
return keyboard;
}

/**
* Retrieve a preset virtual keyboard.
*
* @param language
* @return vk
*/
@RequestMapping(value = "data/virtualkeyboardPreset", method = RequestMethod.POST)
public @ResponseBody List<String[]> virtualKeyboardPreset(String language) {
File virtualKeyboard = new File(fileManager.getVirtualKeyboardFile(language));

List<String[]> keyboard = new ArrayList<>();
try(BufferedReader br = new BufferedReader(new FileReader(virtualKeyboard))) {
String st;
while ((st = br.readLine()) != null)
if(st.replace("\\s+", "").length() > 0)
keyboard.add(st.split("\\s+"));
} catch (IOException e) {
e.printStackTrace();
}
return keyboard;
}

/**
* Returns whether LAREX is configured to be used in conjunction with OCR4all or not.
*/
@RequestMapping(value = "config/ocr4all", method = RequestMethod.POST, headers = "Accept=*/*",
produces = "application/json")
public @ResponseBody Boolean isOCR4allMode() {
String ocr4allMode = config.getSetting("ocr4all");
return ocr4allMode.equals("enable");
}
}
51 changes: 51 additions & 0 deletions src/main/java/de/uniwue/web/controller/SegmentationController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package de.uniwue.web.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;

import de.uniwue.algorithm.geometry.regions.RegionSegment;
import de.uniwue.web.io.PageXMLWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -15,13 +23,15 @@
import org.springframework.web.bind.annotation.ResponseBody;

import de.uniwue.web.communication.SegmentationRequest;
import de.uniwue.web.communication.BatchSegmentationRequest;
import de.uniwue.web.config.LarexConfiguration;
import de.uniwue.web.facade.segmentation.LarexFacade;
import de.uniwue.web.facade.segmentation.SegmentationSettings;
import de.uniwue.web.io.FileDatabase;
import de.uniwue.web.io.FilePathManager;
import de.uniwue.web.model.Page;
import de.uniwue.web.model.PageAnnotations;
import org.w3c.dom.Document;

/**
* Communication Controller to handle requests for the main viewer/editor.
Expand Down Expand Up @@ -64,6 +74,47 @@ private void init() {
return LarexFacade.segmentPage(segmentationRequest.getSettings(), segmentationRequest.getPage(), fileManager, database);
}

@RequestMapping(value = "segmentation/batchSegment", method = RequestMethod.POST, headers = "Accept=*/*",
produces = "application/json", consumes = "application/json")
public @ResponseBody List<PageAnnotations> batchSegment(@RequestBody BatchSegmentationRequest batchSegmentationRequest) {
FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()),
config.getListSetting("imagefilter"));
List<PageAnnotations> results = new ArrayList<>();
boolean save = batchSegmentationRequest.getSave();
for(int page: batchSegmentationRequest.getPages()){
PageAnnotations result = LarexFacade.segmentPage(batchSegmentationRequest.getSettings(), page, fileManager, database);
if(save){
try {
final Document pageXML = PageXMLWriter.getPageXML(result, batchSegmentationRequest.getVersion());

final String xmlName = result.getName() + ".xml";

switch (config.getSetting("localsave")) {
case "bookpath":
String bookdir = fileManager.getLocalBooksPath() + File.separator
+ database.getBookName(batchSegmentationRequest.getBookid());
PageXMLWriter.saveDocument(pageXML, xmlName, bookdir);
break;
case "savedir":
String savedir = config.getSetting("savedir");
if (savedir != null && !savedir.equals("")) {
PageXMLWriter.saveDocument(pageXML, xmlName, savedir);
} else {
System.err.println("Warning: Save dir is not set. File could not been saved.");
}
break;
case "none":
case "default":
}
} catch (Exception e) {
e.printStackTrace();
}
};
results.add(result);
}
return results;
}

@RequestMapping(value = "segmentation/settings", method = RequestMethod.POST)
public @ResponseBody SegmentationSettings getBook(@RequestParam("bookid") int bookID) {
FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()),
Expand Down
Loading

0 comments on commit af161d4

Please sign in to comment.