split image to 3 channels opencv error

Hi

I am currently planning on splitting my image into 3 channels so i can get the RGB values of an image to plot a scatter graph so i can model is using a normal distribtion calculating the covariance matrix, mean, etc. then calculate distance between the background points and the actual image to segment the image.

Now in my first task, i have wrote the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
VideoCapture cam(0);
//int id=0;
Mat image, Rch,Gch,Bch;
vector<Mat> rgb(3);         //RGB is a vector of 3 matrices

namedWindow("window");
while(1)
{
    cam>>image;
    split(image,rgb);
    Bch = rgb[0];
    Gch = rgb[1];
    Rch = rgb[2];
}

but as soon as it reaches the split function, i step through it, it causes a unhandled exception error. access violation writing location 0xfeeefeee

i am still new to opencv, so am not used to dealing with unhandled exception error.

thanks

EDIT: i tried adding items into the vector still error, either via push_back or general assignment i.e. rgb[0] = Rch or Bch still error.
Last edited on
looks like your Mat class needs a copy constructor and you didn't specify one. Correct me if I wrong.
@MiiNiPaa: It's `cv::Mat' and it does have a proper copy constructor.

@OP: Your code looks fine, try to provide a test case.
i did and it still resulted in an error
i think its something to do with the split function i don't know

I have gaussian distribution for my background model i want to remove and want to access each pixel and enter it into gaussian formula to calculate probability if it belongs in background or not.

so i thought split it and check the value of each channel. then i was told a better way was to access each pixel directly without split using vector which i did.

1
2
3
4
5
6
7
8
9
vector<float> pixel(3);

for(i=1;i<image.rows;i++)
{
    for(j=1;j<image.cols;j++)
    {
        pixel[0] = image.at<Vec3b>(i,j)[0];
     }
}

it doesn't work, gives 0 value, but when i do run it, which image taken from camera, the terminal shows wierd characters if i replace pixel[0] with cout << or most of the time it prints out blank characters.

any help would be appreciated thanks
Last edited on
> i did and it still resulted in an error
¿you did what?


If you want to debug, use a debugger.
The value may not be a graphical character.


The problem is in line 42.
I'm not sure if split in OpenCV takes in a vector as an argument.
I see here.
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=split#split

it says OutputArrayofArrays. Not sure if that is same as vector
@ne555
when i say i did i tried initializing the vector still got error. I stepped through the code line by line via debug and it crashes trying to execute split()

@xkcd83
i think it is the same thing. i am using a matrix and the vector contains matrix so i am using a matrix not a vector. but use vector to hold matrix.

Topic archived. No new replies allowed.