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

asked 2018-05-03 08:02:36 -0600

nevind7 gravatar image

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!

edit retag flag offensive close merge delete

Comments

it's somewhat unclear, why you're doing this, and what output you need exactly.

berak gravatar imageberak ( 2018-05-03 08:23:51 -0600 )edit
1

It's actually a program for my Father, he is measuring changes in light intensity over x amount of time.

Here is an example of what the output is. Each row consists of a frame. Across each row is all the summed up values of each column of the ROI. So in this output, you can image (from left>right) that it's dark, then get's brighter and brighter as you go across the ROI.

https://imgur.com/a/06GU18I

nevind7 gravatar imagenevind7 ( 2018-05-03 08:29:43 -0600 )edit

you image shows a cumulative sum for each row, but your code is calculating the sum per pixel

berak gravatar imageberak ( 2018-05-03 10:24:20 -0600 )edit

so, a cumulative, row-wise sum.

and the problem is ?

berak gravatar imageberak ( 2018-05-03 10:25:08 -0600 )edit

Do you know what direction I should be going in? I imagine it's just some logic error. For example, when I put something completely black over my camera, the output is

206 212 650 626 656 882 666 661 890 882 666 661 890 882 666 661 888 884 666 661 890 882 666 661 890 882 666 661 890 884 666 661 893 884 666 661 890 884 666 661 888

Clearly not what I am going for lol

nevind7 gravatar imagenevind7 ( 2018-05-03 10:49:20 -0600 )edit