i detecting text using pipeline google codelabs sample code. how preview frame camerasource sends textrecognizer?
the preview frame not sent beyond text recognizer. however, make class wraps text recognizer, receiving preview frame before detection. see similar discussion here.
first, implement detector class wrap text recognizer:
class mytextrecognizer extends detector<textblock> { private detector<textblock> mdelegate; mytextrecognizer(detector<textblock> delegate) { mdelegate = delegate; } public sparsearray<textblock> detect(frame frame) { // *** add code access preview frame here return mdelegate.detect(frame); } public boolean isoperational() { return mdelegate.isoperational(); } public boolean setfocus(int id) { return mdelegate.setfocus(id); } }
wrap text recognizer class, , pass class camera source. this:
textrecognizer textrecognizer = new textrecognizer.builder(context) .build(); textrecognizer mytextrecognizer = new mytextrecognizer(textrecognizer); mytextrecognizer.setprocessor(/* include processor here */); mcamerasource = new camerasource.builder(context, mytextrecognizer) .build();
your mytextrecognizer called first raw frame data.
note image may not upright, if device rotated. can orientation through frame's metadata.getrotation method.
one word of caution: once detect method returns, should not access frame pixel data. since camera source recycles image buffers, contents of frame object overridden once method returns.
Comments
Post a Comment