0
点赞
收藏
分享

微信扫一扫

NV12 大图上扣取小图


// src 原始数据 是nv12 的YUV数据,直接从手机摄像头采集的数据
// dest 截取的数据 开辟的空间大小为(x1 - x0 + 1) * (y1 - y0 + 1)包含两边的点
// srcW 原始数据的宽
// srcH 原始数据的高
// x0 y0 左上角的坐标点 (必须是偶数)
// x1 y1 右下角的坐标点 (必须是奇数)
#define CLAMP(a, s, m) ((a) < (s)? (s) : ((a) > (m) ? (m) : (a)))
int NV12CutImage(unsigned char * src, unsigned char * dest, int srcW, int srcH, int x0, int y0, int x1, int y1)
{
    int dstw = 0;
    int dsth = 0;
    int i = 0;
    int j = 0;
    int k = 0;
    int srcwh = 0;
    int dstwh = 0;

    dstw = x1 - x0 + 1;
    dsth = y1 - y0 + 1;

    unsigned char * srcUV = src + srcW * srcH;
    unsigned char * destUV = dest + dstw * dsth;

    for (i = y0; i <= y1; i++)
    {
        for (j = x0; j <= x1; j++)
        {
            dest[(i - y0) * dstw + (j - x0)] = src[i * srcW + j];

            destUV[((i - y0) / 2 * (dstw / 2) + (j - x0) / 2) * 2 + 0] = srcUV[((i / 2) * (srcW / 2) + (j / 2)) * 2 + 0];

            destUV[((i - y0) / 2 * (dstw / 2) + (j - x0) / 2) * 2 + 1] = srcUV[((i / 2) * (srcW / 2) + (j / 2)) * 2 + 1];

        }
    }


    return 0;

}

参考:https://blog.csdn.net/baidu_31872269/article/details/70214701?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-70214701-blog-125795158.235^v38^pc_relevant_sort&spm=1001.2101.3001.4242.1&utm_relevant_index=3

举报

相关推荐

0 条评论