Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

split r g b matrix from rgb image

 Mat image; 
  Mat grayFrame;
  Mat blue_matrix ;
  Mat diffFrame;
  image = cv_ptr->image;
  float max=0;
//obtain luminosity image and blue matrix and diffframe of blue and luminance 
  for (int row = 0; row<=479; row++)
  {
    for (int col =0; col<=639; col++)
    {
        Vec3f color_value = image.at<Vec3f>(row, col);
        int blue = color_value.val[0];
        int green = color_value.val[1];
        int red = color_value.val[2];
        grayFrame.at<int>(row,col) = round (0.21*red + 0.72*green + 0.07 * blue); 
        blue_matrix.at<int>(row,col) = blue;
        cout << blue<< "       "<<endl;
}}

Hi, I have a bgr image and want to split into r g b matrice and convert original matrix to grayscale. However , this code gives me core dump error because of these lines

grayFrame.at<int>(row,col) = round (0.21red + 0.72green + 0.07 * blue); blue_matrix.at<int>(row,col) = blue;

Also, i notice the blue value is weird. This is the value i obtained -2147483648 -2147483648.

Anyone help me with this problem please

click to hide/show revision 2
No.2 Revision

updated 2015-09-23 00:07:31 -0600

berak gravatar image

split r g b matrix from rgb image

 Mat image; 
  Mat grayFrame;
  Mat blue_matrix ;
  Mat diffFrame;
  image = cv_ptr->image;
  float max=0;
//obtain luminosity image and blue matrix and diffframe of blue and luminance 
  for (int row = 0; row<=479; row++)
  {
    for (int col =0; col<=639; col++)
    {
        Vec3f color_value = image.at<Vec3f>(row, col);
        int blue = color_value.val[0];
        int green = color_value.val[1];
        int red = color_value.val[2];
        grayFrame.at<int>(row,col) = round (0.21*red + 0.72*green + 0.07 * blue); 
        blue_matrix.at<int>(row,col) = blue;
        cout << blue<< "       "<<endl;
}}

Hi, I have a bgr image and want to split into r g b matrice and convert original matrix to grayscale. However , this code gives me core dump error because of these lines

grayFrame.at<int>(row,col) = round (0.21red + 0.72green (0.21*red + 0.72*green + 0.07 * blue); 
         blue_matrix.at<int>(row,col) = blue;

blue;

Also, i notice the blue value is weird. This is the value i obtained -2147483648 -2147483648.

Anyone help me with this problem please