Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Summing BGR in each column of ROI? openCV C++

I am trying to sum together the BGR values of the entire column of a ROI of a camera image. Right now, I loop through the matrix, and assign each BGR value to a variable to put into my 2d vector. I am sure I am doing this wrong, and that there is a much better way.

Vec3b rgbVal;

    for (int r = 0; r < img1.rows; ++r) {
        vector <double> colVal;
        for (int c = 0; c < img1.cols; ++c) {
            rgbVal = img1.at<Vec3b>(r, c); //Converts Mat image to Vec3b for BRG access
            //Accesses the BRG values of each pixel in the column of the ROI, and adds it to values
            values += static_cast<double>(rgbVal[0]) + static_cast<double>(rgbVal[1]) + static_cast<double>(rgbVal[2]);
            colVal.push_back(values);
        }
        j.push_back(colVal);
        values = 0;
    }

So in my ROI, I am trying to sum together ALL the BGR values of every pixel in each column. Can someone help me out with this and point me in the right direction?

Thanks!