微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

数组到图像的替代方案

如何解决数组到图像的替代方案

对于一个项目,我使用的是 MLX90461 红外摄像头。 我正在使用一些 C++ 代码来读取相机的数据。

此相机的数据存储在 192 个元素 (16x12 RES) 的数组中。 在这个数组中,我存储了该像素的测量温度。

接下来,我将该温度转换为 RGB 值并存储这些值。 因为我每个像素需要 3 个值,所以数组有 576 个元素。 (192 * 3).

所以现在我有一个充满数据的数组。我想为所有这些数据制作一个图像。

我遵循了 this 示例,效果很好。

现在来了但是……但是:

  1. 输出一个 .ppm 文件
  2. 输出只有 16x12 像素

而且我想将输出用作一种实时流,因此 .ppm 文件类型不是很好。

所以我的问题是。

  1. 这种做事方式是否朝着正确的方向发展?
  2. 有没有办法输出更“常见”的文件类型,比如 .png
  3. C++ 是进行此类数据处理的最佳方式吗? 我正在考虑使用 Python 制作基于数组的图像。

我想要的最终结果是这样的:visualization on display(见下面的 GIF 代码

void print_pixels(){
    static uint8_t pixels[576];
    uint16_t l = 0;
    for(int i = 0 ; i < 12 ; i++){ //rows
        for(int j = 0 ; j < 16 ; j++){ // cols
            struct CRGB color = tempToColor(temperatures[j+16*i]);
            pixels[l] = color.r;
            L++;
            pixels[l] = color.g;
            L++;
            pixels[l] = color.b;
            L++;
            printf("T%4.2f,R%i,G%i,B%i : ",temperatures[j+16*i],pixels[l - 3],pixels[l - 2],pixels[l - 1]);
        }
        std::cout << "\n\n";
    }

    FILE *imageFile;
    int height=12,width=16;

    imageFile=fopen("/home/pI/Output_IR_camera.ppm","wb");
    if(imageFile==NULL){
        perror("ERROR: Cannot open output file");
        exit(1);
    }
    fprintf(imageFile,"P6\n");               // P6 filetype
    fprintf(imageFile,"%d %d\n",width,height);   // dimensions
    fprintf(imageFile,"255\n");              // Max pixel

    fwrite(pixels,1,576,imageFile);
    fclose(imageFile);

}

struct CRGB tempToColor(float temp) {
    struct CRGB color;
    if (temp > MAX_TEMP) {
        color.r = 255;
        color.g = 0;
        color.b = 255;
    } else if (temp >= MIN_TEMP + PEAK_STEPS * 4) {
        color.r = round(255 * (temp - (MIN_TEMP + PEAK_STEPS * 4.0)) / PEAK_STEPS);
        color.g = 0;
        color.b = 255;
    } else if (temp >= MIN_TEMP + PEAK_STEPS * 3) {
        color.r = 0;
        color.g = round(255 * (6 - (temp - (MIN_TEMP + PEAK_STEPS * 3.0)) / PEAK_STEPS));
        color.b = 255;
    } else if (temp >= MIN_TEMP + PEAK_STEPS * 2) {
        color.r = 0;
        color.g = 255;
        color.b = round(255 * (temp - (MIN_TEMP + PEAK_STEPS * 2.0)) / PEAK_STEPS);
    } else if (temp >= MIN_TEMP + PEAK_STEPS * 1) {
        color.r = round(255 * (6 - (temp - (MIN_TEMP + PEAK_STEPS * 1.0)) / PEAK_STEPS));
        color.g = 255;
        color.b = 0;
    } else if (temp >= MIN_TEMP) {
        color.r = 255;
        color.g = round(255 * ((temp - MIN_TEMP) / PEAK_STEPS));
        color.b = 0;
    } else {
        color.r = 255;
        color.g = 0;
        color.b = 0;
    }
    return color;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。