Преобразование растровых данных в RGB Visual C ++ - PullRequest
1 голос
/ 08 января 2020

Я пытаюсь взять растровое изображение и получить значения RGB пикселей. То, что у меня сейчас есть, откроет файл растрового изображения и прочитает данные пикселей:

#define _CRT_SECURE_NO_DEPRECATE

#include "findColor.h"

#include <vector>
#include <iostream>
int findColor(std::string path) {
    std::vector<std::string> averageColor; //Will hold the average hex color of each image in order.

    std::string currentImage;


    currentImage = path + std::to_string(i) + ".btm";

    FILE* f = fopen(currentImage.c_str(), "rb");
    unsigned char info[54]; //Bitmap header is 54 bytes
    fread(info, sizeof(unsigned char), 54, f); //reading the header

    // extract image height and width from header
    int width, height;
    memcpy(&width, info + 18, sizeof(int));
    memcpy(&height, info + 22, sizeof(int));
        int heightSign = 1;
    if (height < 0) {
        heightSign = -1;
    }
    int size = 3 * width * height; //size of image in bytes. 3 bytes per pixel.
    unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel
    fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
        fclose(f); //close image.

    for (i = 0; i < size; i += 3) //Flip the image data? It is stored as BGR flipping it to RGB?
    {
        unsigned char tmp = data[i-33];
        data[i] = data[i + 2];
        data[i + 2] = tmp;
    }

    return 0;

}

Я действительно не знаю, где отсюда go. Любые ответы будут оценены.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...