Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions android/src/org/tensorflow/demo/ClassifierActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public void drawCallback(final Canvas canvas) {
public void onImageAvailable(final ImageReader reader) {
Image image = null;

final int yRowStride;
final int uvRowStride;
final int uvPixelStride;

try {
image = reader.acquireLatestImage();

Expand All @@ -195,19 +199,9 @@ public void onImageAvailable(final ImageReader reader) {
final Plane[] planes = image.getPlanes();
fillBytes(planes, yuvBytes);

final int yRowStride = planes[0].getRowStride();
final int uvRowStride = planes[1].getRowStride();
final int uvPixelStride = planes[1].getPixelStride();
ImageUtils.convertYUV420ToARGB8888(
yuvBytes[0],
yuvBytes[1],
yuvBytes[2],
previewWidth,
previewHeight,
yRowStride,
uvRowStride,
uvPixelStride,
rgbBytes);
yRowStride = planes[0].getRowStride();
uvRowStride = planes[1].getRowStride();
uvPixelStride = planes[1].getPixelStride();

image.close();
} catch (final Exception e) {
Expand All @@ -219,19 +213,30 @@ public void onImageAvailable(final ImageReader reader) {
return;
}

rgbFrameBitmap.setPixels(rgbBytes, 0, previewWidth, 0, 0, previewWidth, previewHeight);
final Canvas canvas = new Canvas(croppedBitmap);
canvas.drawBitmap(rgbFrameBitmap, frameToCropTransform, null);

// For examining the actual TF input.
if (SAVE_PREVIEW_BITMAP) {
ImageUtils.saveBitmap(croppedBitmap);
}

runInBackground(
new Runnable() {
@Override
public void run() {
ImageUtils.convertYUV420ToARGB8888(
yuvBytes[0],
yuvBytes[1],
yuvBytes[2],
previewWidth,
previewHeight,
yRowStride,
uvRowStride,
uvPixelStride,
rgbBytes);

rgbFrameBitmap.setPixels(rgbBytes, 0, previewWidth, 0, 0, previewWidth, previewHeight);
final Canvas canvas = new Canvas(croppedBitmap);
canvas.drawBitmap(rgbFrameBitmap, frameToCropTransform, null);

// For examining the actual TF input.
if (SAVE_PREVIEW_BITMAP) {
ImageUtils.saveBitmap(croppedBitmap);
}

final long startTime = SystemClock.uptimeMillis();
final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap);
lastProcessingTimeMs = SystemClock.uptimeMillis() - startTime;
Expand Down