opencv - split a BGR matrix without use split() function -
i programming visual studio 2012 , opencv library, in 2.4.6 version.
someone can me splitting bgr image 3 images, 1 every channel?
i know there split function in opencv, causes me unhandled exception, because have 64 bit processor 32 bit library, or it's version of library, want know how iterate on pixel values of bgr matrix without use split().
thanks in advance.
if don't want use split() can read each r,g,b pixel value source image , write destination image , should single channel.
#include <stdio.h> #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, const char** argv ){ mat src = imread("ball.jpg", 1); mat r(src.rows,src.cols,cv_8uc1); mat g(src.rows,src.cols,cv_8uc1); mat b(src.rows,src.cols,cv_8uc1); for(int i=0;i<src.rows;i++){ for(int j=0;j<src.cols;j++){ vec3b pixel = src.at<vec3b>(i, j); b.at<uchar>(i,j) = pixel[0]; g.at<uchar>(i,j) = pixel[1]; r.at<uchar>(i,j) = pixel[2]; } } imshow("src", src); imshow("r", r); imshow("g", g); imshow("b", b); waitkey(0); }
Comments
Post a Comment