android - 使用 Libyuv 将 YUV_420 _888 转换为 ARGB

标签 android android-camera yuv argb libyuv

我正在通过调用 Libyuv 库中的方法 I420ToARGB 来处理以 YUV_420 _888 编码的 Android camera2 预览帧,但我得到的图像颜色错误。

 libyuv::I420ToARGB(
    ysrc, //const uint8* src_y,
    ystride, //int src_stride_y,
    usrc, //const uint8* src_u,
    ustride, ///int src_stride_u,
    vsrc, //const uint8* src_v,
    vstride, //int src_stride_v,
    argb, //uint8* dst_argb,
    w*4, //int dst_stride_argb,
    w, //int width,
    h //int height
);

最佳答案

如果红色对象显示为蓝色,反之亦然,则 U 和 V 颜色平面倒置。根据 Android 开发者文档,这些平面是:

http://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888

The order of planes in the array returned by Image#getPlanes() is guaranteed such that plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).

另外,这个 libyuv 方法似乎不支持像素步幅,对于 YUY_420_888 图像,像素步幅可能大于 1。在这种情况下,当像素步幅大于 1 时,您需要将平面预处理为连续,或者使用一种方法接受来自 libyuv 的半平面 420(如果存在)。

关于android - 使用 Libyuv 将 YUV_420 _888 转换为 ARGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36119735/

相关文章:

android - Admob 中介中的自定义事件添加不受支持的广告网络

java - 将 SQL 值添加到 ArrayList,然后检查它们是否存在

android - 在 CameraPreview 上应用 EffectFactory 效果

java - 相机参数 setRotation() 方法不会旋转 onPreviewFrame() 中收到的帧

opencv - 在 OPENCV 中加载 RAW YUV 视频

android - 我如何区分 imageReader 相机 API 2 中的 NV21 和 YV12 编码?

c - FFMPEG使用sws_scale将YCbCr转换为RGB

java - 如何在TeeChart中设置标题的阴影颜色?

java - Android 应用程序开发、动态按钮和字段

android - Nexus 4手机上没有调用onPreviewFrame…而是在模拟器上