-1

I am trying to make an Histogram that is represented by a Cube of size 256*256*256, every position in the Cube represents a color. Thus from an Image I want to fill the frequency of each color in a position but I have trouble converting the BGR vector of each pixel into an int so I can access the Cube positions

typedef std::vector<std::vector<std::vector<int>>> CubeType;
typedef cv::Mat MatType;
typedef cv::Vec3b ColorType;

Histogram::Histogram(MatType const& image, int binSize){
    aHist = CubeType(binSize, std::vector<std::vector<int>>(binSize, std::vector<int>(binSize, 0)));
    aBinSize = binSize; // int
    for(int i = 0; i < image.cols; ++i){
        for(int j = 0; j < image.rows; ++j){
            ColorType color = image.at<ColorType>(j, i);
        }
    }
}

I need a way to convert the cv::Vec3b into three integers

int b, g, r;

or a way to get a different cv:: vector that represents integers.

polmonroig
  • 937
  • 4
  • 12
  • 22

1 Answers1

-1

Its a Vector with 3 entries. Usually BGR (could be RBG or HSV, but OpenCV defaults to BGR for images) values so you can reference them like you would an array.

int b = color[0];
int g = color[1];
int r = color[2];

See this answer for detailed help.

ias
  • 314
  • 2
  • 14
  • 1
    Once you have indentified the question as a duplicate, please flag it as such and DON'T write an answer -- that's rather counterproductive. – Dan Mašek Nov 05 '18 at 12:56