Created
October 8, 2011 17:40
-
-
Save felipe-araujo/1272605 to your computer and use it in GitHub Desktop.
OpenCV RBG image channel splitting(C++)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VideoCapture cap(0); | |
if(!cap.isOpened()) exit(0); | |
cap.set(CV_CAP_PROP_FRAME_WIDTH, 250); | |
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 250); | |
cout << "Frame width: " << cap.get(CV_CAP_PROP_FRAME_WIDTH) << endl; | |
cout << "Frame height: " << cap.get(CV_CAP_PROP_FRAME_HEIGHT) << endl; | |
Mat in; | |
vector<Mat> rgb; | |
cap >> in; | |
rgb.push_back( Mat(in.rows, in.cols, CV_8UC1)); | |
rgb.push_back( Mat(in.rows, in.cols, CV_8UC1)); | |
rgb.push_back( Mat(in.rows, in.cols, CV_8UC1)); | |
rgb.push_back( Mat(in.rows, in.cols, CV_8UC1)); | |
namedWindow("original", 1); | |
namedWindow("red", 1); | |
namedWindow("green", 1); | |
namedWindow("blue", 1); | |
for(;;){ | |
cap >> in; | |
imshow("original", in); | |
split(in, rgb); | |
// not sure if this is the rigth order | |
imshow("red", rgb.at(2)); | |
imshow("green", rgb.at(1)); | |
imshow("blue", rgb.at(0)); | |
if(waitKey(30) >= 0) break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment