yuv二值化操作

UV是色差分量,UV为0就会全是绿色,全为0x80的时候才能看到灰度图。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

int show_hex(char* begin, int len)
{
    int i = 0;
    for (i = 0; i < len; i++)
    {
        printf("%02x ", begin[i]);
    }
    printf("\n");

    return 0;
}

int write_file(const char* path, char* buffer, int len)
{
    FILE* fp = fopen(path, "w+");
    assert(fp);
    int ret = fwrite(buffer, 1, len, fp);
    assert(ret == len);
    fclose(fp);

    return 0;
}

int cover(char* dst, int d_width, int d_height, int x, int y, char* src, int s_width, int s_height)
{
    int i = 0;
    int j = 0;

    for (i = 0; i < s_height; i++)
    {
        int idx = x*d_width + y;
        for (j = 0; j < s_width; j++)
        {
            dst[idx++] = src[i*s_width+j];
        }
        x++;
    }

    return 0;
}

int main()
{
    int width = 1280;
    int height = 720;
    int size = width*height*1.5;
    char* buffer = (char*)malloc(size);
    assert(buffer);
    memset(buffer, 0x80, size);// uv 需设置为0x80
    memset(buffer, 0xff, width*height); // 设置Y 为0xff(白色)

    char tmp[16*16];
    memset(tmp, 0, 16*16); // 设置cover 为0(黑色)
    cover(buffer, width, height, 0, 0, tmp, 16, 16);

    write_file("test.yuv", buffer, size);
    free(buffer);

    return 0;
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值