首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过libyuv::I420Scale为android前置摄像头实现镜像?

如何通过libyuv::I420Scale为android前置摄像头实现镜像?
EN

Stack Overflow用户
提问于 2015-10-26 09:21:13
回答 1查看 1.3K关注 0票数 1

以下单词来自libyuv#rotation

镜像-水平翻转镜功能的水平翻转图像,这可能是有用的‘自我查看’的网络摄像头。

代码语言:javascript
复制
int I420Mirror(const uint8* src_y, int src_stride_y,
           const uint8* src_u, int src_stride_u,
           const uint8* src_v, int src_stride_v,
           uint8* dst_y, int dst_stride_y,
           uint8* dst_u, int dst_stride_u,
           uint8* dst_v, int dst_stride_v,
           int width, int height);

镜像功能也可以通过传递负宽度和/或高度通过I420Scale和ARGBScale函数来实现。

但是,我看到了这样的I420Scale实现:

代码语言:javascript
复制
LIBYUV_API
int I420Scale(const uint8* src_y, int src_stride_y,
          const uint8* src_u, int src_stride_u,
          const uint8* src_v, int src_stride_v,
          int src_width, int src_height,
          uint8* dst_y, int dst_stride_y,
          uint8* dst_u, int dst_stride_u,
          uint8* dst_v, int dst_stride_v,
          int dst_width, int dst_height,
          enum FilterMode filtering) {
  int src_halfwidth = SUBSAMPLE(src_width, 1, 1);
  int src_halfheight = SUBSAMPLE(src_height, 1, 1);
  int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1);
  int dst_halfheight = SUBSAMPLE(dst_height, 1, 1);
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || 
  src_width > 32768 || src_height > 32768 ||
  !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { 
    return -1;
  }

  ScalePlane(src_y, src_stride_y, src_width, src_height,
         dst_y, dst_stride_y, dst_width, dst_height,
         filtering);
  ScalePlane(src_u, src_stride_u, src_halfwidth, src_halfheight,
         dst_u, dst_stride_u, dst_halfwidth, dst_halfheight,
         filtering);
  ScalePlane(src_v, src_stride_v, src_halfwidth, src_halfheight,
         dst_v, dst_stride_v, dst_halfwidth, dst_halfheight,
         filtering);
  return 0;
}

若为dst_width <= 0 || dst_height <= 0,则为return -1

这是关于Mirror functionality can also be achieved with the I420Scale by passing negative width and/or height的笑话吗?

如何用I420Scale实现镜像功能?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-26 11:22:39

在我这样做之后,它对我很好,如下所示:

代码语言:javascript
复制
if (facing == 1) {
    // front camera should be mirror
    src_w = - src_w;
}
if ((ret = I420Scale(
            pTempY, src_stride_y,
            pTempU, src_stride_u,
            pTempV, src_stride_v,
            src_w, src_h,
            pDstY, dst_width,
            pDstU, (dst_width + 1) >> 1,
            pDstV, (dst_width + 1) >> 1,
            dst_w, dst_h,
            kFilterNone
        ))) {}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33342214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档