Search in sources :

Example 21 with JochreException

use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.

the class ImageUtils method getImage.

/**
 * Get an image from a sql query which selects only the image itself.
 */
public static BufferedImage getImage(NamedParameterJdbcTemplate jt, String sql, MapSqlParameterSource paramSource, String column) {
    BufferedImage image = null;
    byte[] pixels = jt.query(sql, paramSource, new ResultSetExtractor<byte[]>() {

        @Override
        public byte[] extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (rs.next()) {
                byte[] pixels = rs.getBytes("image_image");
                return pixels;
            } else {
                return null;
            }
        }
    });
    ByteArrayInputStream is = new ByteArrayInputStream(pixels);
    try {
        image = ImageIO.read(is);
        is.close();
    } catch (IOException e) {
        throw new JochreException(e);
    }
    return image;
}
Also used : JochreException(com.joliciel.jochre.utils.JochreException) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) DataAccessException(org.springframework.dao.DataAccessException)

Example 22 with JochreException

use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.

the class ImageUtils method storeImage.

/**
 * Store the image in a MapSqlParameterSource for usage in an insert/update
 * query.
 */
public static void storeImage(MapSqlParameterSource paramSource, String varName, BufferedImage image) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", os);
        os.flush();
        paramSource.addValue(varName, os.toByteArray());
        os.close();
    } catch (IOException e) {
        throw new JochreException(e);
    }
}
Also used : JochreException(com.joliciel.jochre.utils.JochreException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 23 with JochreException

use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.

the class ImageUtils method getImage.

/**
 * Get the image from a previously retrieved ResultSet.
 */
public static BufferedImage getImage(ResultSet rs, String column) throws SQLException {
    BufferedImage image = null;
    if (rs.getObject(column) != null) {
        byte[] imageBytes = rs.getBytes(column);
        ByteArrayInputStream is = new ByteArrayInputStream(imageBytes);
        try {
            image = ImageIO.read(is);
            is.close();
        } catch (IOException e) {
            throw new JochreException(e);
        }
    }
    return image;
}
Also used : JochreException(com.joliciel.jochre.utils.JochreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

JochreException (com.joliciel.jochre.utils.JochreException)23 IOException (java.io.IOException)15 BufferedImage (java.awt.image.BufferedImage)7 File (java.io.File)7 ClassificationModel (com.joliciel.talismane.machineLearning.ClassificationModel)5 Shape (com.joliciel.jochre.graphics.Shape)4 ClassificationEventStream (com.joliciel.talismane.machineLearning.ClassificationEventStream)4 ClassificationModelTrainer (com.joliciel.talismane.machineLearning.ClassificationModelTrainer)4 ModelTrainerFactory (com.joliciel.talismane.machineLearning.ModelTrainerFactory)4 BoundaryDetector (com.joliciel.jochre.boundaries.BoundaryDetector)3 DeterministicBoundaryDetector (com.joliciel.jochre.boundaries.DeterministicBoundaryDetector)3 LetterByLetterBoundaryDetector (com.joliciel.jochre.boundaries.LetterByLetterBoundaryDetector)3 OriginalBoundaryDetector (com.joliciel.jochre.boundaries.OriginalBoundaryDetector)3 JochreImage (com.joliciel.jochre.graphics.JochreImage)3 LetterFeature (com.joliciel.jochre.letterGuesser.features.LetterFeature)3 LetterFeatureParser (com.joliciel.jochre.letterGuesser.features.LetterFeatureParser)3 TreeSet (java.util.TreeSet)3 BeamSearchImageAnalyser (com.joliciel.jochre.analyser.BeamSearchImageAnalyser)2 ImageAnalyser (com.joliciel.jochre.analyser.ImageAnalyser)2 LetterAssigner (com.joliciel.jochre.analyser.LetterAssigner)2