Search in sources :

Example 6 with JochreImage

use of com.joliciel.jochre.graphics.JochreImage in project jochre by urieli.

the class JochrePage method segment.

/**
 * For any Image on this page, segments it by converting to a JochreImage.
 */
public void segment() {
    int i = 0;
    for (JochreImage image : this.getImages()) {
        SourceImage sourceImage = (SourceImage) image;
        Segmenter segmenter = new Segmenter(sourceImage, jochreSession);
        segmenter.segment();
        LOG.debug("Image " + i + " segmented: " + sourceImage.getName());
        i++;
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) SourceImage(com.joliciel.jochre.graphics.SourceImage) Segmenter(com.joliciel.jochre.graphics.Segmenter)

Example 7 with JochreImage

use of com.joliciel.jochre.graphics.JochreImage in project jochre by urieli.

the class JochrePage method save.

@Override
public void save() {
    if (this.document != null && this.documentId == 0)
        this.documentId = this.document.getId();
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    documentDao.saveJochrePage(this);
    if (this.jochreImages != null) {
        for (JochreImage jochreImage : this.jochreImages) {
            jochreImage.save();
        }
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage)

Example 8 with JochreImage

use of com.joliciel.jochre.graphics.JochreImage in project jochre by urieli.

the class JochrePage method segmentAndShow.

/**
 * Segment any image on this page and output the segmentation into PNG files
 * so that they can be viewed by the user.
 */
public void segmentAndShow(String outputDirectory) {
    int i = 0;
    for (JochreImage image : this.getImages()) {
        SourceImage sourceImage = (SourceImage) image;
        Segmenter segmenter = new Segmenter(sourceImage, jochreSession);
        segmenter.setDrawSegmentation(true);
        segmenter.segment();
        BufferedImage segmentedImage = segmenter.getSegmentedImage();
        try {
            ImageIO.write(segmentedImage, "PNG", new File(outputDirectory + "/" + image.getName() + "_seg.png"));
        } catch (IOException e) {
            throw new JochreException(e);
        }
        LOG.debug("Image " + i + " segmented: " + sourceImage.getName());
        i++;
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) JochreException(com.joliciel.jochre.utils.JochreException) SourceImage(com.joliciel.jochre.graphics.SourceImage) Segmenter(com.joliciel.jochre.graphics.Segmenter) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 9 with JochreImage

use of com.joliciel.jochre.graphics.JochreImage in project jochre by urieli.

the class TextController method onTimer$startRenderTimer.

@Listen("onTimer = #startRenderTimer")
public void onTimer$startRenderTimer(Event event) {
    try {
        progressBox.setVisible(true);
        if (currentImage != null) {
            Html html = new Html();
            StringWriter out = new StringWriter();
            DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
            textGetter.onImageComplete(currentImage);
            html.setContent(out.toString());
            htmlContent.appendChild(html);
            progressMeter1.setValue(100);
        // progressBox.setVisible(false);
        } else {
            if (currentPageIndex < currentDoc.getPages().size()) {
                JochrePage page = currentDoc.getPages().get(currentPageIndex);
                for (JochreImage image : page.getImages()) {
                    Html html = new Html();
                    StringWriter out = new StringWriter();
                    DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
                    textGetter.onImageComplete(image);
                    out.append("<HR/>");
                    html.setContent(out.toString());
                    htmlContent.appendChild(html);
                }
                page.clearMemory();
                currentPageIndex++;
                double percentComplete = ((double) currentPageIndex / (double) currentDoc.getPages().size()) * 100;
                progressMeter1.setValue(new Double(percentComplete).intValue());
                startRenderTimer.setRunning(true);
            } else {
                progressMeter1.setValue(100);
            // progressBox.setVisible(false);
            }
        }
    } catch (Exception e) {
        LOG.error("Failure in onTimer$startRenderTimer", e);
        throw new RuntimeException(e);
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) StringWriter(java.io.StringWriter) DocumentObserver(com.joliciel.jochre.doc.DocumentObserver) Html(org.zkoss.zul.Html) JochrePage(com.joliciel.jochre.doc.JochrePage) TextGetter(com.joliciel.jochre.output.TextGetter) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 10 with JochreImage

use of com.joliciel.jochre.graphics.JochreImage in project jochre by urieli.

the class JochreDocument method deletePage.

public void deletePage(JochrePage page) {
    if (!page.getDocument().equals(this)) {
        throw new RuntimeException("Cannot delete page from document - page is on another document");
    }
    for (JochreImage image : page.getImages()) {
        this.graphicsDao.deleteJochreImage(image);
    }
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    documentDao.deleteJochrePage(page);
    this.getPages().remove(page);
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage)

Aggregations

JochreImage (com.joliciel.jochre.graphics.JochreImage)20 Shape (com.joliciel.jochre.graphics.Shape)12 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 JochrePage (com.joliciel.jochre.doc.JochrePage)7 JochreSession (com.joliciel.jochre.JochreSession)6 JochreDocument (com.joliciel.jochre.doc.JochreDocument)6 GroupOfShapes (com.joliciel.jochre.graphics.GroupOfShapes)6 Paragraph (com.joliciel.jochre.graphics.Paragraph)6 RowOfShapes (com.joliciel.jochre.graphics.RowOfShapes)6 Config (com.typesafe.config.Config)6 BufferedImage (java.awt.image.BufferedImage)6 SourceImage (com.joliciel.jochre.graphics.SourceImage)4 TreeSet (java.util.TreeSet)4 SplitFeature (com.joliciel.jochre.boundaries.features.SplitFeature)3 Segmenter (com.joliciel.jochre.graphics.Segmenter)3 Decision (com.joliciel.talismane.machineLearning.Decision)3 DecisionMaker (com.joliciel.talismane.machineLearning.DecisionMaker)3 StringWriter (java.io.StringWriter)3 DocumentObserver (com.joliciel.jochre.doc.DocumentObserver)2