use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class ChupchikLowerRightFeature method checkInternal.
@Override
public FeatureResult<Boolean> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
int xSectors = 11;
int centreSectors = 13;
int marginSectors = 1;
double[][] grid = shape.getBrightnessBySection(xSectors, centreSectors, marginSectors, SectionBrightnessMeasurementMethod.RELATIVE_TO_MAX_SECTION);
double minChupchikStart = 8;
boolean foundChupchik = false;
for (int j = grid[0].length - 1; j >= grid[0].length - 5; j--) {
boolean foundBlack = false;
int chupchikSize = 0;
for (int i = grid.length - 1; i > 0; i--) {
if (!foundBlack && i < minChupchikStart)
break;
if (grid[i][j] >= 0.5) {
foundBlack = true;
chupchikSize++;
} else if (grid[i][j] < 0.5 && foundBlack) {
break;
}
}
if (LOG.isTraceEnabled())
LOG.trace("Row " + j + ", chupchickSize: " + chupchikSize);
if (foundBlack && chupchikSize <= 3) {
foundChupchik = true;
break;
} else if (foundBlack) {
break;
}
}
FeatureResult<Boolean> outcome = this.generateResult(foundChupchik);
return outcome;
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class EmptySectorsBinaryFeature method checkInternal.
@Override
public FeatureResult<Boolean> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
double[][] totals = shape.getBrightnessBySection(5, 5, 1, SectionBrightnessMeasurementMethod.RAW);
Mean testMean = new Mean();
Mean otherMean = new Mean();
for (int i = 0; i < totals.length; i++) {
for (int j = 0; j < totals[0].length; j++) {
double brightness = totals[i][j];
if (testSectors[i][j])
testMean.increment(brightness);
else if (brightness > shape.getBrightnessMeanBySection(5, 5, 1, SectionBrightnessMeasurementMethod.RAW))
otherMean.increment(brightness);
}
}
double testMeanValue = testMean.getResult();
double otherMeanValue = otherMean.getResult();
if (LOG.isDebugEnabled())
LOG.trace("Test mean: " + testMeanValue + " (* threshold = " + testMeanValue * THRESHOLD + "), Other mean: " + otherMeanValue);
boolean result = (testMeanValue * THRESHOLD < otherMeanValue);
FeatureResult<Boolean> outcome = this.generateResult(result);
return outcome;
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class FixTextWindowController method onClick$btnOK.
@Listen("onClick = #btnOK")
public void onClick$btnOK(Event event) {
// TODO: replacing all occurrences of the same word on the line instead
// of just the current one
LOG.debug("onClick$btnOK");
winFixText.setVisible(false);
String rowText = (String) winFixText.getAttribute(FixTextWindowController.ATTR_ROW_TEXT);
Textbox rowTextBox = (Textbox) winFixText.getAttribute(FixTextWindowController.ATTR_ROW_TEXTBOX);
LetterLabelUpdater updater = (LetterLabelUpdater) winFixText.getAttribute(FixTextWindowController.ATTR_LETTER_UPDATER);
GroupOfShapes group = (GroupOfShapes) winFixText.getAttribute(FixTextWindowController.ATTR_GROUP);
group.setSkip(chkSkip.isChecked());
group.setHardHyphen(chkHardHyphen.isChecked());
group.setBrokenWord(chkBrokenWord.isChecked());
group.setSegmentationProblem(chkSegmentProblem.isChecked());
group.save();
List<Textbox> letterBoxes = new ArrayList<Textbox>();
for (Object child : letterBoxRow.getChildren()) {
if (child instanceof Textbox) {
letterBoxes.add((Textbox) child);
}
}
StringBuilder sb = new StringBuilder();
// for (Textbox letterBox : letterBoxes) {
for (Shape shape : group.getShapes()) {
Textbox letterBox = (Textbox) letterBoxRow.getFellow("FixTextLetterBox_" + shape.getId());
String letter = letterBox.getText();
String newLetter = ImageController.getLetterForDisplay(letter);
LOG.debug("Letter: " + letter + ", newLetter: " + newLetter);
sb.append(newLetter);
}
LOG.debug(sb.toString());
String newText = rowText.replace(FixTextWindowController.ROW_TEXT_PLACE_HOLDER, sb.toString());
rowTextBox.setText(newText);
updater.updateLetterLabels();
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class Jochre method doCommandLogImage.
/**
* Log a shape's image to the log file, to make sure it got segmented and stored
* correctly.
*/
public void doCommandLogImage(int shapeId) {
// correctly
if (shapeId > 0) {
GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
Shape shape = graphicsDao.loadShape(shapeId);
shape.writeImageToLog();
LOG.debug("Letter: " + shape.getLetter());
}
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class Jochre method doCommandTestFeature.
/**
* Test a feature on a particular shape.
*/
public void doCommandTestFeature(int shapeId) {
// just a utility for testing a feature on a particular shape
ShapeFeature<?> feature = new VerticalElongationFeature();
GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
if (shapeId > 0) {
Shape shape = graphicsDao.loadShape(shapeId);
shape.writeImageToLog();
RuntimeEnvironment env = new RuntimeEnvironment();
feature.check(shape, env);
} else {
// String result = "false";
// TrainingServiceLocator trainingServiceLocator =
// locator.getTrainingServiceLocator();
// TrainingService trainingService =
// trainingServiceLocator.getTrainingService();
// List<Integer> shapeIds =
// trainingService.findShapesForFeature("ג", feature, result);
List<Integer> shapeIds = graphicsDao.findShapeIds("—");
Map<Object, Integer> outcomeMap = new HashMap<>();
for (int oneShapeId : shapeIds) {
Shape shape = graphicsDao.loadShape(oneShapeId);
shape.writeImageToLog();
RuntimeEnvironment env = new RuntimeEnvironment();
FeatureResult<?> weightedOutcome = feature.check(shape, env);
Object outcome = weightedOutcome.getOutcome();
Integer count = outcomeMap.get(outcome);
if (count == null)
outcomeMap.put(outcome, 1);
else
outcomeMap.put(outcome, count.intValue() + 1);
}
LOG.debug("Outcomes:");
for (Object outcome : outcomeMap.keySet()) {
LOG.debug("Outcome " + outcome.toString() + ", count " + outcomeMap.get(outcome));
}
}
}
Aggregations