use of org.opencastproject.metadata.mpeg7.VideoTextImpl in project opencast by opencast.
the class TextAnalyzerServiceImpl method analyze.
/**
* Returns the video text element for the given image.
*
* @param imageFile
* the image
* @param id
* the video text id
* @return the video text found on the image
* @throws TextAnalyzerException
* if accessing the image fails
*/
protected VideoText[] analyze(File imageFile, String id) throws TextAnalyzerException {
/* Call the text extractor implementation to extract the text from the
* provided image file */
List<VideoText> videoTexts = new ArrayList<VideoText>();
TextFrame textFrame = null;
try {
textFrame = textExtractor.extract(imageFile);
} catch (IOException e) {
logger.warn("Error reading image file {}: {}", imageFile, e.getMessage());
throw new TextAnalyzerException(e);
} catch (TextExtractorException e) {
logger.warn("Error extracting text from {}: {}", imageFile, e.getMessage());
throw new TextAnalyzerException(e);
}
/* Get detected text as raw string */
int i = 1;
for (TextLine line : textFrame.getLines()) {
if (line.getText() != null) {
VideoText videoText = new VideoTextImpl(id + "-" + i++);
videoText.setBoundary(line.getBoundaries());
Textual text = dictionaryService.cleanUpText(line.getText());
if (text != null) {
videoText.setText(text);
videoTexts.add(videoText);
}
}
}
return videoTexts.toArray(new VideoText[videoTexts.size()]);
}
Aggregations