「已注销」 2022-01-09 20:21 采纳率: 66.7%
浏览 37
已结题

请问这样生成出的yuv文件为什么是原来的1/20?

代码如下,是我的储存方式有问题嘛?

```c++

#include<iostream>
#include<fstream>

using namespace std;
typedef struct YUVPixel {
    int Y;
    int U;
    int V;
} YUVPixel;
int main()
{
    FILE* orignal_data = fopen("ParkScene_1920x1080_24_16bit_444.yuv", "r");
    FILE* f_r = fopen("r_data.yuv", "w");
    if (orignal_data == NULL)
        printf("open file error:\n");
    unsigned int width = 1920, height = 1080;
    unsigned char* raw_16bit_pixels = (unsigned char*)malloc(width * height * 3 * sizeof(unsigned char));
    fread(raw_16bit_pixels, 1, width * height * 3, orignal_data); //暂时忽略其返回值
    YUVPixel yuv_pixel;
    unsigned char Ylow, Yhigh,Ulow,Uhigh,Vlow,Vhigh;
    unsigned int Ytemp,Utemp,Vtemp;
    for (int j = 0;j < height;j++)
        for (int i = 0;i < width;i++)
        {
            yuv_pixel.Y = raw_16bit_pixels[1920 * j + i];//读入Y
            yuv_pixel.U = raw_16bit_pixels[1920 * j + i + 1920 * 1080];//读入U
            yuv_pixel.V = raw_16bit_pixels[1920 * j + i + 1920 * 1080 * 2];//读入V
            Ylow = (yuv_pixel.Y )& 0xff;
            Yhigh = (yuv_pixel.Y )>> 8;
            Ytemp = Yhigh;
            Ytemp <<= 8;
            Ytemp += Ylow;//Y的合成
            Ulow = (yuv_pixel.U) & 0xff;
            Uhigh = (yuv_pixel.U) >> 8;
            Utemp = Uhigh;
            Utemp <<= 8;
            Utemp += Ulow;//U的合成
            Vlow = (yuv_pixel.V) & 0xff;
            Vhigh = (yuv_pixel.V) >> 8;
            Vtemp = Uhigh;
            Vtemp <<= 8;
            Vtemp += Vlow;//V的合成
          //  cout << Utemp << "比较" << yuv_pixel.U << endl;
            fputc(Ytemp, f_r);//写入Y
            fputc(Utemp, f_r);//写入U
            fputc(Vtemp, f_r);//写入V
        }
    fclose(f_r);
    return 0;
}

```

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2022-01-09 20:31
    关注

    之前文件中颜色分量0-255是用整形存储的,每个分量4字节,改写后,颜色分量改用字符型存储,每个分量1个字节。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 1月9日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。