user2544764
user2544764

Reputation: 21

opencv - rgb value keeps changing

I'm having some problem with the rgb or in opencv bgr

What I'm trying to do is find the overall value of the bgr of a certain pictures but every time I run the program without changing anything with exact same pictures the values of the bgr keeps changing..

This is how i coded to find the values of bgr

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace std;
    char path[255];

int main( int argc, char** argv )
{
    IplImage *red[50];
    IplImage *green[50];
    IplImage *blue[50];

    for(int i = 1; i <= 50; i++)
    {
        IplImage *img;
        sprintf(path, "C:\\picture (%01).bmp", i);
        img = cvLoadImage(path);
        red[i] = cvCreateImage(cvGetSize(img), 8, 1);
        green[i] = cvCreateImage(cvGetSize(img), 8, 1);
        blue[i] = cvCreateImage(cvGetSize(img), 8, 1);
        cvSplit(img, blue[i], green[i], red[i], NULL);
        cvReleaseImage(&img);

        int total = (int)(blue[i]) + (int)(green[i]) + (int)(red[i]);
        cout << total << endl;
        cvWaitKey(1);
    }
cvWaitKey(0);
return 0;
}

Upvotes: 0

Views: 169

Answers (2)

Mojo Jojo
Mojo Jojo

Reputation: 489

Try using two loops instead of one, one for loading the images and the other for performing your operation, and let me know if it works..

Upvotes: 0

baci
baci

Reputation: 2588

I am not sure how did you achieve type casting from IplImage to int

int total = (int)(blue[i]) + (int)(green[i]) + (int)(red[i]);

but you certainly need to use pixel by pixel summation for each channel (not image by image) to find the overall values.

Upvotes: 1

Related Questions