鱼眼去锯齿

#include 

// 定义图像分辨率
#define WIDTH 3000
#define HEIGHT 3000

int main()
{
    FILE *fin, *fout;
    int32_t x, y;

    // 加载 YUV 文件
    fin = fopen("test.yuv", "rb");
    if (fin == NULL) {
        fprintf(stderr, "Failed to open input file.\n");
        return -1;
    }

    // 读取所有像素数据,以及 U/V 分量数据
    uint8_t (*y_data)[WIDTH] = malloc(HEIGHT * sizeof(*y_data));
    uint8_t (*u_data)[WIDTH/2] = malloc(HEIGHT/2 * sizeof(*u_data));
    uint8_t (*v_data)[WIDTH/2] = malloc(HEIGHT/2 * sizeof(*v_data));

    fread(y_data, sizeof(uint8_t), HEIGHT * WIDTH, fin);
    fread(u_data, sizeof(uint8_t), HEIGHT/2 * WIDTH/2, fin);
    fread(v_data, sizeof(uint8_t), HEIGHT/2 * WIDTH/2, fin);

    fclose(fin);

    // 读取包含坐标点信息的文件
    fin = fopen("output2.txt", "r");
    if (fin == NULL) {
        fprintf(stderr, "Failed to open coordinate file.\n");
        return -1;
    }

    // 将指定像素点的 Y、U、V 值设置为指定值
    while (fscanf(fin, "(%d,%d)\n", &x, &y) == 2) {
        if (x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
            continue;  // 跳过越界点
        }
        y_data[y][x] = 17;
        u_data[y/2][x/2] = 128;
        v_data[y/2][x/2] = 128;
    }

    fclose(fin);

    // 将修改后的像素数据写回到 YUV 文件中
    fout = fopen("output.yuv", "wb");
    if (fout == NULL) {
        fprintf(stderr, "Failed to open output file.\n");
        return -1;
    }

    fwrite(y_data, sizeof(uint8_t), HEIGHT * WIDTH, fout);
    fwrite(u_data, sizeof(uint8_t), HEIGHT/2 * WIDTH/2, fout);
    fwrite(v_data, sizeof(uint8_t), HEIGHT/2 * WIDTH/2, fout);

    fclose(fout);

    // 释放动态申请的内存
    free(y_data);
    free(u_data);
    free(v_data);

    return 0;
}

你可能感兴趣的:(linux)