当前位置: 首页>>代码示例>>Java>>正文


Java Plane类代码示例

本文整理汇总了Java中android.media.Image.Plane的典型用法代码示例。如果您正苦于以下问题:Java Plane类的具体用法?Java Plane怎么用?Java Plane使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Plane类属于android.media.Image包,在下文中一共展示了Plane类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fillBytes

import android.media.Image.Plane; //导入依赖的package包/类
protected void fillBytes(final Plane[] planes, final byte[][] yuvBytes) {
  // Because of the variable row stride it's not possible to know in
  // advance the actual necessary dimensions of the yuv planes.
  for (int i = 0; i < planes.length; ++i) {
    final ByteBuffer buffer = planes[i].getBuffer();
    if (yuvBytes[i] == null) {
      LOGGER.d("Initializing buffer %d at size %d", i, buffer.capacity());
      yuvBytes[i] = new byte[buffer.capacity()];
    }
    buffer.get(yuvBytes[i]);
  }
}
 
开发者ID:Jamjomjara,项目名称:snu-artoon,代码行数:13,代码来源:CameraActivity.java

示例2: onImageAvailable

import android.media.Image.Plane; //导入依赖的package包/类
@Override
public void onImageAvailable(final ImageReader reader) {
  Image image = null;

  try {
    image = reader.acquireLatestImage();

    if (image == null) {
      return;
    }

    if (computing) {
      image.close();
      return;
    }
    computing = true;

    Trace.beginSection("imageAvailable");

    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],
        rgbBytes,
        previewWidth,
        previewHeight,
        yRowStride,
        uvRowStride,
        uvPixelStride,
        false);

    image.close();
  } catch (final Exception e) {
    if (image != null) {
      image.close();
    }
    LOGGER.e(e, "Exception!");
    Trace.endSection();
    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() {
          final long startTime = SystemClock.uptimeMillis();
          final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap);
          lastProcessingTimeMs = SystemClock.uptimeMillis() - startTime;

          cropCopyBitmap = Bitmap.createBitmap(croppedBitmap);
          resultsView.setResults(results);
          requestRender();
          computing = false;
        }
      });

  Trace.endSection();
}
 
开发者ID:apacha,项目名称:TensorflowAndroidDemo,代码行数:74,代码来源:ClassifierActivity.java

示例3: onImageAvailable

import android.media.Image.Plane; //导入依赖的package包/类
/**
 * Callback for Camera2 API
 */
@Override
public void onImageAvailable(final ImageReader reader) {
  //We need wait until we have some size from onPreviewSizeChosen
  if (previewWidth == 0 || previewHeight == 0) {
    return;
  }
  if (rgbBytes == null) {
    rgbBytes = new int[previewWidth * previewHeight];
  }
  try {
    final Image image = reader.acquireLatestImage();

    if (image == null) {
      return;
    }

    if (isProcessingFrame) {
      image.close();
      return;
    }
    isProcessingFrame = true;
    Trace.beginSection("imageAvailable");
    final Plane[] planes = image.getPlanes();
    fillBytes(planes, yuvBytes);
    yRowStride = planes[0].getRowStride();
    final int uvRowStride = planes[1].getRowStride();
    final int uvPixelStride = planes[1].getPixelStride();

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

    postInferenceCallback =
        new Runnable() {
          @Override
          public void run() {
            image.close();
            isProcessingFrame = false;
          }
        };

    processImage();
  } catch (final Exception e) {
    LOGGER.e(e, "Exception!");
    Trace.endSection();
    return;
  }
  Trace.endSection();
}
 
开发者ID:Nilhcem,项目名称:tensorflow-classifier-android,代码行数:66,代码来源:CameraActivity.java

示例4: onImageAvailable

import android.media.Image.Plane; //导入依赖的package包/类
@Override public void onImageAvailable(final ImageReader reader) {
  imageReader = reader;

  Image image = null;

  try {
    image = reader.acquireLatestImage();

    if (image == null) {
      return;
    }

    if (savingImage || computing) {
      image.close();
      return;
    }
    savingImage = true;

    Trace.beginSection("imageAvailable");

    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], rgbBytes,
        previewWidth, previewHeight, yRowStride, uvRowStride, uvPixelStride, false);

    image.close();
  } catch (final Exception e) {
    if (image != null) {
      image.close();
    }
    LOGGER.e(e, "Exception!");
    Trace.endSection();
    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);
  }

  savingImage = false;
  Trace.endSection();
}
 
开发者ID:flipper83,项目名称:SortingHatAndroid,代码行数:52,代码来源:CameraActivity.java

示例5: onImageAvailable

import android.media.Image.Plane; //导入依赖的package包/类
@Override
public void onImageAvailable(final ImageReader reader) {
    Image image = null;

    try {
        image = reader.acquireLatestImage();

        if (image == null) {
            return;
        }

        if (computing) {
            image.close();
            return;
        }
        computing = true;

        Trace.beginSection("imageAvailable");

        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],
                rgbBytes,
                previewWidth,
                previewHeight,
                yRowStride,
                uvRowStride,
                uvPixelStride,
                false);

        image.close();
    } catch (final Exception e) {
        if (image != null) {
            image.close();
        }
        LOGGER.e(e, "Exception!");
        Trace.endSection();
        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() {
                    final long startTime = SystemClock.uptimeMillis();
                    final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap);
                    lastProcessingTimeMs = SystemClock.uptimeMillis() - startTime;

                    cropCopyBitmap = Bitmap.createBitmap(croppedBitmap);
                    resultsView.setResults(results);
                    requestRender();
                    computing = false;
                }
            });

    Trace.endSection();
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:74,代码来源:CameraClassifierActivity.java

示例6: onImageAvailable

import android.media.Image.Plane; //导入依赖的package包/类
@Override
public void onImageAvailable(final ImageReader reader) {
  Image image = null;

  try {
    image = reader.acquireLatestImage();

    if (image == null) {
      return;
    }

    if (computing) {
      image.close();
      return;
    }
    computing = true;

    Trace.beginSection("imageAvailable");

    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);

    image.close();
  } catch (final Exception e) {
    if (image != null) {
      image.close();
    }
    LOGGER.e(e, "Exception!");
    Trace.endSection();
    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() {
          final long startTime = SystemClock.uptimeMillis();
          final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap);
          lastProcessingTimeMs = SystemClock.uptimeMillis() - startTime;

          cropCopyBitmap = Bitmap.createBitmap(croppedBitmap);
          resultsView.setResults(results);

          requestRender();
          computing = false;
        }
      });

  Trace.endSection();
}
 
开发者ID:PallabPaul,项目名称:AI_Calorie_Counter_Demo,代码行数:74,代码来源:ClassifierActivity.java

示例7: compressJpegFromYUV420Image

import android.media.Image.Plane; //导入依赖的package包/类
/**
 * Compresses the given image to jpeg. Note that only ImageFormat.YUV_420_888 is currently
 * supported. Furthermore, all planes must use direct byte buffers.
 *
 * @param img the image to compress
 * @param outBuf a direct byte buffer to hold the output jpeg.
 * @return The number of bytes written to outBuf
 */
public static int compressJpegFromYUV420Image(Image img, ByteBuffer outBuf, int quality) {
    if (img.getFormat() != ImageFormat.YUV_420_888) {
        throw new RuntimeException("Unsupported Image Format.");
    }

    final int NUM_PLANES = 3;

    if (img.getPlanes().length != NUM_PLANES) {
        throw new RuntimeException("Output buffer must be direct.");
    }

    if (!outBuf.isDirect()) {
        throw new RuntimeException("Output buffer must be direct.");
    }

    ByteBuffer[] planeBuf = new ByteBuffer[NUM_PLANES];
    int[] pixelStride = new int[NUM_PLANES];
    int[] rowStride = new int[NUM_PLANES];

    for (int i = 0; i < NUM_PLANES; i++) {
        Plane plane = img.getPlanes()[i];

        if (!plane.getBuffer().isDirect()) {
            return -1;
        }

        planeBuf[i] = plane.getBuffer();
        pixelStride[i] = plane.getPixelStride();
        rowStride[i] = plane.getRowStride();
    }

    outBuf.clear();

    int numBytesWritten = compressJpegFromYUV420p(
            img.getWidth(), img.getHeight(),
            planeBuf[0], pixelStride[0], rowStride[0],
            planeBuf[1], pixelStride[1], rowStride[1],
            planeBuf[2], pixelStride[2], rowStride[2],
            outBuf, quality);

    outBuf.limit(numBytesWritten);

    return numBytesWritten;
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:53,代码来源:JpegUtilNative.java


注:本文中的android.media.Image.Plane类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。