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.21*red + 0.72*green + 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
at<something>()
calls is using the correct type (Vec3b instead of Vec3f, uchar instead of int).opencv is a high level library, please avoid writing per-pixel loops like above but use existing functions properly. you could just do:
and be done.