#include #include int main(int argc, char* argv[]) { char* windowNames[] = { "band 0", "band 1", "band 2" }; printf("Hit ESC key to quit ...\n"); // Pick one of these two input sources; comment out the other line. // Note - the movie file goes into the directory with your source code. cv::VideoCapture cap(0); // open the default camera //cv::VideoCapture cap("131023-124754.avi"); // open a movie file if(!cap.isOpened()) {// check if we succeeded printf("error - can't open the input source\n"); system("PAUSE"); return -1; } double WIDTH = cap.get(CV_CAP_PROP_FRAME_WIDTH); double HEIGHT = cap.get(CV_CAP_PROP_FRAME_HEIGHT); printf("Image width=%f, height=%f\n", WIDTH, HEIGHT); // Create image windows. Meaning of flags: //CV_WINDOW_NORMAL enables manual resizing; CV_WINDOW_AUTOSIZE is automatic // You can "or" the above choice with CV_WINDOW_KEEPRATIO, which keeps aspect ratio cv::namedWindow("Input image", CV_WINDOW_AUTOSIZE); // Run an infinite loop until user hits the ESC key while (1){ cv::Mat imgInput; cap >> imgInput;// get image from camera if (imgInput.empty()) break; cv::imshow("Input image", imgInput); // Split into planes cv::Mat planes[3]; split( imgInput, planes ); // Show images in the windows for (int i=0; i<3; i++) cv::imshow(windowNames[i], planes[i]); // wait for x ms (0 means wait until a keypress) if (cv::waitKey(33) == 27) break;// ESC is ascii 27 } return EXIT_SUCCESS; }